27 require_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/modules_genpassword.php';
64 public $WithoutAmbi = 0;
93 $this->length = $langs->trans(
"SetupPerso");
97 $this->langs = $langs;
100 if (empty($conf->global->USER_PASSWORD_PATTERN)) {
102 dolibarr_set_const($db,
"USER_PASSWORD_PATTERN",
'12;1;1;1;3;1',
'chaine', 0,
'', $conf->entity);
105 $this->Maj =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
106 $this->Min = strtolower($this->Maj);
107 $this->Nb =
"0123456789";
108 $this->Spe =
"!@#$%&*()_-+={}[]\\|:;'/";
109 $this->Ambi = array(
"1",
"I",
"l",
"|",
"O",
"0");
111 $tabConf = explode(
";", $conf->global->USER_PASSWORD_PATTERN);
112 $this->length2 = $tabConf[0];
113 $this->NbMaj = $tabConf[1];
114 $this->NbNum = $tabConf[2];
115 $this->NbSpe = $tabConf[3];
116 $this->NbRepeat = $tabConf[4];
117 $this->WithoutAmbi = $tabConf[5];
127 if ($this->WithoutAmbi) {
128 $this->Maj = str_replace($this->Ambi,
"", $this->Maj);
129 $this->Min = str_replace($this->Ambi,
"", $this->Min);
130 $this->Nb = str_replace($this->Ambi,
"", $this->Nb);
131 $this->Spe = str_replace($this->Ambi,
"", $this->Spe);
134 $pattern = $this->Min.(!empty($this->NbMaj) ? $this->Maj :
'').(!empty($this->NbNum) ? $this->Nb :
'').(!empty($this->NbSpe) ? $this->Spe :
'');
135 $this->All = str_shuffle($pattern);
146 return $langs->trans(
"PasswordGenerationPerso");
169 for ($i = 0; $i < $this->NbMaj; $i++) {
171 $pass .= $this->Maj[mt_rand(0, strlen($this->Maj) - 1)];
174 for ($i = 0; $i < $this->NbNum; $i++) {
176 $pass .= $this->Nb[mt_rand(0, strlen($this->Nb) - 1)];
179 for ($i = 0; $i < $this->NbSpe; $i++) {
181 $pass .= $this->Spe[mt_rand(0, strlen($this->Spe) - 1)];
184 for ($i = strlen($pass); $i < $this->length2; $i++) {
186 $pass .= $this->All[mt_rand(0, strlen($this->All) - 1)];
189 $pass = str_shuffle($pass);
211 $password_a = preg_split(
'//u', $password,
null, PREG_SPLIT_NO_EMPTY);
212 $maj = preg_split(
'//u', $this->Maj,
null, PREG_SPLIT_NO_EMPTY);
213 $num = preg_split(
'//u', $this->Nb,
null, PREG_SPLIT_NO_EMPTY);;
214 $spe = preg_split(
'//u', $this->Spe,
null, PREG_SPLIT_NO_EMPTY);
223 $langs->load(
"other");
224 $this->error = $langs->trans(
"YourPasswordMustHaveAtLeastXChars", $this->length2);
228 if (count(array_intersect($password_a, $maj)) < $this->NbMaj) {
229 $langs->load(
"other");
230 $this->error = $langs->trans(
'PasswordNeedAtLeastXUpperCaseChars', $this->NbMaj);
234 if (count(array_intersect($password_a, $num)) < $this->NbNum) {
235 $langs->load(
"other");
236 $this->error = $langs->trans(
'PasswordNeedAtLeastXDigitChars', $this->NbNum);
240 if (count(array_intersect($password_a, $spe)) < $this->NbSpe) {
241 $langs->load(
"other");
242 $this->error = $langs->trans(
'PasswordNeedAtLeastXSpecialChars', $this->NbSpe);
247 $langs->load(
"other");
248 $this->error = $langs->trans(
'PasswordNeedNoXConsecutiveChars', $this->NbRepeat);
265 if (empty($this->NbRepeat)) {
269 $char = preg_split(
'//u', $password,
null, PREG_SPLIT_NO_EMPTY);
273 foreach ($char as $c) {
284 if ($count > $this->NbRepeat) {