27 require_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/modules_genpassword.php';
76 $this->length = $langs->trans(
"SetupPerso");
80 $this->langs = $langs;
83 if (empty($conf->global->USER_PASSWORD_PATTERN)) {
85 dolibarr_set_const($db,
"USER_PASSWORD_PATTERN",
'10;1;1;1;3;1',
'chaine', 0,
'', $conf->entity);
88 $this->Maj =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
89 $this->Min = strtolower($this->Maj);
90 $this->Nb =
"0123456789";
91 $this->Spe =
"!@#$%&*()_-+={}[]\\|:;'/";
92 $this->Ambi = array(
"1",
"I",
"l",
"|",
"O",
"0");
94 $tabConf = explode(
";", $conf->global->USER_PASSWORD_PATTERN);
95 $this->length2 = $tabConf[0];
96 $this->NbMaj = $tabConf[1];
97 $this->NbNum = $tabConf[2];
98 $this->NbSpe = $tabConf[3];
99 $this->NbRepeat = $tabConf[4];
100 $this->WithoutAmbi = $tabConf[5];
102 if ($this->WithoutAmbi)
104 $this->Maj = str_replace($this->Ambi,
"", $this->Maj);
105 $this->Min = str_replace($this->Ambi,
"", $this->Min);
106 $this->Nb = str_replace($this->Ambi,
"", $this->Nb);
107 $this->Spe = str_replace($this->Ambi,
"", $this->Spe);
110 $pattern = $this->Min.(!empty($this->NbMaj) ? $this->Maj :
'').(!empty($this->NbNum) ? $this->Nb :
'').(!empty($this->NbSpe) ? $this->Spe :
'');
111 $this->All = str_shuffle($pattern);
126 return $langs->trans(
"PasswordGenerationPerso");
147 for ($i = 0; $i < $this->NbMaj; $i++) {
149 $pass .= $this->Maj[mt_rand(0, strlen($this->Maj) - 1)];
152 for ($i = 0; $i < $this->NbNum; $i++) {
154 $pass .= $this->Nb[mt_rand(0, strlen($this->Nb) - 1)];
157 for ($i = 0; $i < $this->NbSpe; $i++) {
159 $pass .= $this->Spe[mt_rand(0, strlen($this->Spe) - 1)];
162 for ($i = strlen($pass); $i < $this->length2; $i++) {
164 $pass .= $this->All[mt_rand(0, strlen($this->All) - 1)];
167 $pass = str_shuffle($pass);
184 $password_a = str_split($password);
185 $maj = str_split($this->Maj);
186 $num = str_split($this->Nb);
187 $spe = str_split($this->Spe);
189 if (count(array_intersect($password_a, $maj)) < $this->NbMaj) {
193 if (count(array_intersect($password_a, $num)) < $this->NbNum) {
197 if (count(array_intersect($password_a, $spe)) < $this->NbSpe) {
218 if (empty($this->NbRepeat))
return 1;
221 $char = str_split($password);
223 foreach ($char as $c) {
232 if ($count > $this->NbRepeat) {
Parent class for password rules/management modules.
Class to generate a password according to personal rules.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
validatePassword($password)
Validate a password.
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).
$conf db
API class for accounts.
consecutiveInterationSameCharacter($password)
Check the consecutive iterations of the same character.
getNewGeneratedPassword()
Build new password.
getExample()
Return an example of password generated by this module.
__construct($db, $conf, $langs, $user)
Constructor.
getDescription()
Return description of module.