27require_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/modules_genpassword.php';
40 public $picto =
'fa-shield-alt';
66 public $WithoutAmbi = 0;
95 $this->length = $langs->trans(
"SetupPerso");
99 $this->langs = $langs;
102 if (empty($conf->global->USER_PASSWORD_PATTERN)) {
104 dolibarr_set_const($db,
"USER_PASSWORD_PATTERN",
'12;1;1;0;3;1',
'chaine', 0,
'', $conf->entity);
107 $this->Maj =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
108 $this->Min = strtolower($this->Maj);
109 $this->Nb =
"0123456789";
110 $this->Spe =
"!@#$%&*()_-+={}[]\\|:;'/";
111 $this->Ambi = array(
"1",
"I",
"l",
"|",
"O",
"0");
113 $tabConf = explode(
";", $conf->global->USER_PASSWORD_PATTERN);
114 $this->length2 = $tabConf[0];
115 $this->NbMaj = $tabConf[1];
116 $this->NbNum = $tabConf[2];
117 $this->NbSpe = $tabConf[3];
118 $this->NbRepeat = $tabConf[4];
119 $this->WithoutAmbi = $tabConf[5];
129 if ($this->WithoutAmbi) {
130 $this->Maj = str_replace($this->Ambi,
"", $this->Maj);
131 $this->Min = str_replace($this->Ambi,
"", $this->Min);
132 $this->Nb = str_replace($this->Ambi,
"", $this->Nb);
133 $this->Spe = str_replace($this->Ambi,
"", $this->Spe);
136 $pattern = $this->Min.(!empty($this->NbMaj) ? $this->Maj :
'').(!empty($this->NbNum) ? $this->Nb :
'').(!empty($this->NbSpe) ? $this->Spe :
'');
137 $this->All = str_shuffle($pattern);
148 return $langs->trans(
"PasswordGenerationPerso");
171 for ($i = 0; $i < $this->NbMaj; $i++) {
173 $pass .= $this->Maj[mt_rand(0, strlen($this->Maj) - 1)];
176 for ($i = 0; $i < $this->NbNum; $i++) {
178 $pass .= $this->Nb[mt_rand(0, strlen($this->Nb) - 1)];
181 for ($i = 0; $i < $this->NbSpe; $i++) {
183 $pass .= $this->Spe[mt_rand(0, strlen($this->Spe) - 1)];
186 for ($i = strlen($pass); $i < $this->length2; $i++) {
188 $pass .= $this->All[mt_rand(0, strlen($this->All) - 1)];
191 $pass = str_shuffle($pass);
213 $password_a = preg_split(
'//u', $password,
null, PREG_SPLIT_NO_EMPTY);
214 $maj = preg_split(
'//u', $this->Maj,
null, PREG_SPLIT_NO_EMPTY);
215 $num = preg_split(
'//u', $this->Nb,
null, PREG_SPLIT_NO_EMPTY);
216 $spe = preg_split(
'//u', $this->Spe,
null, PREG_SPLIT_NO_EMPTY);
225 $langs->load(
"other");
226 $this->error = $langs->trans(
"YourPasswordMustHaveAtLeastXChars", $this->length2);
230 if (count(array_intersect($password_a, $maj)) < $this->NbMaj) {
231 $langs->load(
"other");
232 $this->error = $langs->trans(
'PasswordNeedAtLeastXUpperCaseChars', $this->NbMaj);
236 if (count(array_intersect($password_a, $num)) < $this->NbNum) {
237 $langs->load(
"other");
238 $this->error = $langs->trans(
'PasswordNeedAtLeastXDigitChars', $this->NbNum);
242 if (count(array_intersect($password_a, $spe)) < $this->NbSpe) {
243 $langs->load(
"other");
244 $this->error = $langs->trans(
'PasswordNeedAtLeastXSpecialChars', $this->NbSpe);
249 $langs->load(
"other");
250 $this->error = $langs->trans(
'PasswordNeedNoXConsecutiveChars', $this->NbRepeat);
267 if (empty($this->NbRepeat)) {
271 $char = preg_split(
'//u', $password,
null, PREG_SPLIT_NO_EMPTY);
275 foreach ($char as $c) {
286 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.
conf($dolibarr_main_document_root)
Load conf file (file must exists)