66 return $this->events->triggerResults(
'generate',
'password', [], $generator->generatePassword());
107 $generator->setLength(
strlen($password));
109 return $generator->validatePassword($password);
122 $lower = $this->config->min_password_lower;
123 $upper = $this->config->min_password_upper;
124 $number = $this->config->min_password_number;
125 $special = $this->config->min_password_special;
128 $lower = (int) $lower;
130 $regex .=
'(?!.*[a-z])';
132 $regex .=
'(?=' . str_repeat(
'.*[a-z]', $lower) .
')';
137 $upper = (int) $upper;
139 $regex .=
'(?!.*[A-Z])';
141 $regex .=
'(?=' . str_repeat(
'.*[A-Z]', $upper) .
')';
146 $number = (int) $number;
148 $regex .=
'(?!.*[0-9])';
150 $regex .=
'(?=' . str_repeat(
'.*[0-9]', $number) .
')';
156 $special_chars = $generator->getParameter(RequirementPasswordGenerator::PARAMETER_SYMBOLS);
157 $special_chars =
str_replace(
']',
'\\]', $special_chars);
158 $special_chars =
str_replace(
'-',
'\\-', $special_chars);
160 $special = (int) $special;
162 $regex .=
'(?!.*[' . $special_chars .
'])';
164 $regex .=
'(?=' . str_repeat(
'.*[' . $special_chars .
']', $special) .
')';
168 $length = (int) $this->config->min_password_length;
173 $regex .=
'.{' .
$length .
',}';
186 $result[] = $this->translator->translate(
'password:requirements:min_length', [$this->config->min_password_length]);
188 $lower = $this->config->min_password_lower;
190 $lower = (int) $lower;
192 $result[] = $this->translator->translate(
'password:requirements:lower', [$lower]);
194 $result[] = $this->translator->translate(
'password:requirements:no_lower');
198 $upper = $this->config->min_password_upper;
200 $upper = (int) $upper;
202 $result[] = $this->translator->translate(
'password:requirements:upper', [$upper]);
204 $result[] = $this->translator->translate(
'password:requirements:no_upper');
208 $number = $this->config->min_password_number;
210 $number = (int) $number;
212 $result[] = $this->translator->translate(
'password:requirements:number', [$number]);
214 $result[] = $this->translator->translate(
'password:requirements:no_number');
218 $special = $this->config->min_password_special;
220 $special = (int) $special;
222 $result[] = $this->translator->translate(
'password:requirements:special', [$special]);
224 $result[] = $this->translator->translate(
'password:requirements:no_special');
240 $vars = $event->getValue();
266 $password = $event->getParam(
'password');
284 $generator =
new RequirementPasswordGenerator();
285 $generator->setLength($this->config->min_password_length);
288 $lower = $this->config->min_password_lower;
290 $lower = (int) $lower;
292 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_LOWER_CASE,
false);
294 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_LOWER_CASE,
true);
295 $generator->setMinimumCount(RequirementPasswordGenerator::OPTION_LOWER_CASE, $lower);
300 $upper = $this->config->min_password_upper;
302 $upper = (int) $upper;
304 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_UPPER_CASE,
false);
306 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_UPPER_CASE,
true);
307 $generator->setMinimumCount(RequirementPasswordGenerator::OPTION_UPPER_CASE, $upper);
312 $number = $this->config->min_password_number;
314 $number = (int) $number;
315 if (empty($number)) {
316 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_NUMBERS,
false);
318 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_NUMBERS,
true);
319 $generator->setMinimumCount(RequirementPasswordGenerator::OPTION_NUMBERS, $number);
324 $special = $this->config->min_password_special;
326 $special = (int) $special;
327 if (empty($special)) {
328 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_SYMBOLS,
false);
330 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_SYMBOLS,
true);
331 $generator->setMinimumCount(RequirementPasswordGenerator::OPTION_SYMBOLS, $special);
346 $min_length = (int) $this->config->min_password_length;
348 $requirements_length = (
int) $this->config->min_password_lower;
349 $requirements_length += (int) $this->config->min_password_upper;
350 $requirements_length += (
int) $this->config->min_password_number;
351 $requirements_length += (int) $this->config->min_password_special;
353 return max($min_length, $requirements_length, $length);
364 if (
elgg_strlen($password) < $this->config->min_password_length) {
getGenerator()
Get helper generator.
if(parse_url(elgg_get_site_url(), PHP_URL_PATH)!== '/') if(file_exists(elgg_get_root_path(). 'robots.txt'))
Set robots.txt.
addInputRequirements(\Elgg\Event $event)
Add the security password requirements to an input/password field.
Elgg registration action.
Saves user notification settings.
if(!$item instanceof\ElggEntity) $length
Could not register a new user for whatever reason.
static isEmpty($value)
Check if a value isn't empty, but allow 0 and '0'.
elgg_strlen()
Wrapper function for mb_strlen().
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
validatePasswordLength(string $password)
Validate that a password meets the minimal length requirement.
isValidPassword(string $password)
Validate that a given string matches the password requirements.
generatePassword(int $length=12)
Generate a new random password.
if(!$user||!$user->canEdit()) $password
getValidLength(int $length)
Make sure the password length requirement can be met by the password settings.
Password generator service.
__construct(Config $config, Translator $translator, EventsService $events)
Constructor.
assertValidPassword(string $password)
Assert that a given string matches the password requirements.
getInputRegEx()
Get the regex to set on an input/password to validate password requirements during input...
registerUserPasswordValidation(\Elgg\Event $event)
Validate password during user registration.
getPasswordRequirementsDescription()
Get a description of how a valid password should be made.
Indicate a password string doesn't meet the character requirements.
Indicate a password string doesn't meet the minimal length requirements.
Models an event passed to event handlers.