29require_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/modules_genpassword.php';
42 public $picto =
'fa-shield-alt';
66 public $WithoutAmbi = 0;
104 $this->length = $langs->trans(
"SetupPerso");
108 $this->langs = $langs;
113 dolibarr_set_const($db,
"USER_PASSWORD_PATTERN",
'12;1;1;0;3;1',
'chaine', 0,
'', $conf->entity);
116 $this->Maj =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
117 $this->Min = strtolower($this->Maj);
118 $this->Nb =
"0123456789";
119 $this->Spe =
"!@#$%&*()_-+={}[]\\|:;'/";
120 $this->Ambi = array(
"1",
"I",
"l",
"|",
"O",
"0");
123 $this->length2 = (int) $tabConf[0];
124 $this->NbMaj = $tabConf[1];
125 $this->NbNum = $tabConf[2];
126 $this->NbSpe = $tabConf[3];
127 $this->NbRepeat = $tabConf[4];
128 $this->WithoutAmbi = (int) $tabConf[5];
138 if ($this->WithoutAmbi) {
139 $this->Maj = str_replace($this->Ambi,
"", $this->Maj);
140 $this->Min = str_replace($this->Ambi,
"", $this->Min);
141 $this->Nb = str_replace($this->Ambi,
"", $this->Nb);
142 $this->Spe = str_replace($this->Ambi,
"", $this->Spe);
145 $pattern = $this->Min.(!empty($this->NbMaj) ? $this->Maj :
'').(!empty($this->NbNum) ? $this->Nb :
'').(!empty($this->NbSpe) ? $this->Spe :
'');
146 $this->All = str_shuffle($pattern);
157 return $langs->trans(
"PasswordGenerationPerso");
182 for ($i = 0; $i < $this->NbMaj; $i++) {
184 $pass .= $this->Maj[mt_rand(0, strlen($this->Maj) - 1)];
187 for ($i = 0; $i < $this->NbNum; $i++) {
189 $pass .= $this->Nb[mt_rand(0, strlen($this->Nb) - 1)];
192 for ($i = 0; $i < $this->NbSpe; $i++) {
194 $pass .= $this->Spe[mt_rand(0, strlen($this->Spe) - 1)];
197 for ($i = strlen($pass); $i < $this->length2; $i++) {
199 $pass .= $this->All[mt_rand(0, strlen($this->All) - 1)];
202 $pass = str_shuffle($pass);
224 $password_a = preg_split(
'//u', $password, 0, PREG_SPLIT_NO_EMPTY);
225 $maj = preg_split(
'//u', $this->Maj, 0, PREG_SPLIT_NO_EMPTY);
226 $num = preg_split(
'//u', $this->Nb, 0, PREG_SPLIT_NO_EMPTY);
227 $spe = preg_split(
'//u', $this->Spe, 0, PREG_SPLIT_NO_EMPTY);
236 $langs->load(
"other");
237 $this->error = $langs->trans(
"YourPasswordMustHaveAtLeastXChars", $this->length2);
241 if (count(array_intersect($password_a, $maj)) < $this->NbMaj) {
242 $langs->load(
"other");
243 $this->error = $langs->trans(
'PasswordNeedAtLeastXUpperCaseChars', $this->NbMaj);
247 if (count(array_intersect($password_a, $num)) < $this->NbNum) {
248 $langs->load(
"other");
249 $this->error = $langs->trans(
'PasswordNeedAtLeastXDigitChars', $this->NbNum);
253 if (count(array_intersect($password_a, $spe)) < $this->NbSpe) {
254 $langs->load(
"other");
255 $this->error = $langs->trans(
'PasswordNeedAtLeastXSpecialChars', $this->NbSpe);
260 $langs->load(
"other");
261 $this->error = $langs->trans(
'PasswordNeedNoXConsecutiveChars', $this->NbRepeat);
278 if (empty($this->NbRepeat)) {
282 $char = preg_split(
'//u', $password, 0, PREG_SPLIT_NO_EMPTY);
286 foreach ($char as $c) {
297 if ($count > $this->NbRepeat) {
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
Parent class for password rules/management modules.
Class to generate a password according to personal rules.
validatePassword($password)
Validate a password.
consecutiveIterationSameCharacter($password)
Check the consecutive iterations of the same character.
__construct($db, $conf, $langs, $user)
Constructor.
getExample()
Return an example of password generated by this module.
initAll()
Init the property ->All and clean ->Maj, ->Min, ->Nb and ->Spe with list of valid chars.
getNewGeneratedPassword()
Build new password.
getDescription()
Return description of module.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
$conf db user
Active Directory does not allow anonymous connections.