27require_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/modules_genpassword.php';
40 public $picto =
'fa-shield-alt';
66 public $WithoutAmbi = 0;
86 $this->length = $langs->trans(
"SetupPerso");
90 $this->langs = $langs;
95 dolibarr_set_const($db,
"USER_PASSWORD_PATTERN",
'12;1;1;0;3;1',
'chaine', 0,
'', $conf->entity);
98 $this->Maj =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
99 $this->Min = strtolower($this->Maj);
100 $this->Nb =
"0123456789";
101 $this->Spe =
"!@#$%&*()_-+={}[]\\|:;'/";
102 $this->Ambi = array(
"1",
"I",
"l",
"|",
"O",
"0");
105 $this->length2 = $tabConf[0];
106 $this->NbMaj = $tabConf[1];
107 $this->NbNum = $tabConf[2];
108 $this->NbSpe = $tabConf[3];
109 $this->NbRepeat = $tabConf[4];
110 $this->WithoutAmbi = $tabConf[5];
120 if ($this->WithoutAmbi) {
121 $this->Maj = str_replace($this->Ambi,
"", $this->Maj);
122 $this->Min = str_replace($this->Ambi,
"", $this->Min);
123 $this->Nb = str_replace($this->Ambi,
"", $this->Nb);
124 $this->Spe = str_replace($this->Ambi,
"", $this->Spe);
127 $pattern = $this->Min.(!empty($this->NbMaj) ? $this->Maj :
'').(!empty($this->NbNum) ? $this->Nb :
'').(!empty($this->NbSpe) ? $this->Spe :
'');
128 $this->All = str_shuffle($pattern);
139 return $langs->trans(
"PasswordGenerationPerso");
162 for ($i = 0; $i < $this->NbMaj; $i++) {
164 $pass .= $this->Maj[mt_rand(0, strlen($this->Maj) - 1)];
167 for ($i = 0; $i < $this->NbNum; $i++) {
169 $pass .= $this->Nb[mt_rand(0, strlen($this->Nb) - 1)];
172 for ($i = 0; $i < $this->NbSpe; $i++) {
174 $pass .= $this->Spe[mt_rand(0, strlen($this->Spe) - 1)];
177 for ($i = strlen($pass); $i < $this->length2; $i++) {
179 $pass .= $this->All[mt_rand(0, strlen($this->All) - 1)];
182 $pass = str_shuffle($pass);
204 $password_a = preg_split(
'//u', $password,
null, PREG_SPLIT_NO_EMPTY);
205 $maj = preg_split(
'//u', $this->Maj,
null, PREG_SPLIT_NO_EMPTY);
206 $num = preg_split(
'//u', $this->Nb,
null, PREG_SPLIT_NO_EMPTY);
207 $spe = preg_split(
'//u', $this->Spe,
null, PREG_SPLIT_NO_EMPTY);
216 $langs->load(
"other");
217 $this->error = $langs->trans(
"YourPasswordMustHaveAtLeastXChars", $this->length2);
221 if (count(array_intersect($password_a, $maj)) < $this->NbMaj) {
222 $langs->load(
"other");
223 $this->error = $langs->trans(
'PasswordNeedAtLeastXUpperCaseChars', $this->NbMaj);
227 if (count(array_intersect($password_a, $num)) < $this->NbNum) {
228 $langs->load(
"other");
229 $this->error = $langs->trans(
'PasswordNeedAtLeastXDigitChars', $this->NbNum);
233 if (count(array_intersect($password_a, $spe)) < $this->NbSpe) {
234 $langs->load(
"other");
235 $this->error = $langs->trans(
'PasswordNeedAtLeastXSpecialChars', $this->NbSpe);
240 $langs->load(
"other");
241 $this->error = $langs->trans(
'PasswordNeedNoXConsecutiveChars', $this->NbRepeat);
258 if (empty($this->NbRepeat)) {
262 $char = preg_split(
'//u', $password,
null, PREG_SPLIT_NO_EMPTY);
266 foreach ($char as $c) {
277 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 dolibarr global constant string value.
conf($dolibarr_main_document_root)
Load conf file (file must exists)