52 return $this->events->triggerResults(
'generate',
'password', [], $generator->generatePassword());
93 $generator->setLength(
strlen($password));
95 return $generator->validatePassword($password);
108 $lower = $this->config->min_password_lower;
109 $upper = $this->config->min_password_upper;
110 $number = $this->config->min_password_number;
111 $special = $this->config->min_password_special;
114 $lower = (int) $lower;
116 $regex .=
'(?!.*[a-z])';
118 $regex .=
'(?=' . str_repeat(
'.*[a-z]', $lower) .
')';
123 $upper = (int) $upper;
125 $regex .=
'(?!.*[A-Z])';
127 $regex .=
'(?=' . str_repeat(
'.*[A-Z]', $upper) .
')';
132 $number = (int) $number;
134 $regex .=
'(?!.*[0-9])';
136 $regex .=
'(?=' . str_repeat(
'.*[0-9]', $number) .
')';
142 $special_chars = $generator->getParameter(RequirementPasswordGenerator::PARAMETER_SYMBOLS);
143 $special_chars =
str_replace(
']',
'\\]', $special_chars);
144 $special_chars =
str_replace(
'-',
'\\-', $special_chars);
146 $special = (int) $special;
148 $regex .=
'(?!.*[' . $special_chars .
'])';
150 $regex .=
'(?=' . str_repeat(
'.*[' . $special_chars .
']', $special) .
')';
154 $length = (int) $this->config->min_password_length;
159 $regex .=
'.{' .
$length .
',}';
172 $result[] = $this->translator->translate(
'password:requirements:min_length', [$this->config->min_password_length]);
174 $lower = $this->config->min_password_lower;
176 $lower = (int) $lower;
178 $result[] = $this->translator->translate(
'password:requirements:lower', [$lower]);
180 $result[] = $this->translator->translate(
'password:requirements:no_lower');
184 $upper = $this->config->min_password_upper;
186 $upper = (int) $upper;
188 $result[] = $this->translator->translate(
'password:requirements:upper', [$upper]);
190 $result[] = $this->translator->translate(
'password:requirements:no_upper');
194 $number = $this->config->min_password_number;
196 $number = (int) $number;
198 $result[] = $this->translator->translate(
'password:requirements:number', [$number]);
200 $result[] = $this->translator->translate(
'password:requirements:no_number');
204 $special = $this->config->min_password_special;
206 $special = (int) $special;
208 $result[] = $this->translator->translate(
'password:requirements:special', [$special]);
210 $result[] = $this->translator->translate(
'password:requirements:no_special');
226 $vars = $event->getValue();
252 $password = $event->getParam(
'password');
259 }
catch (\Exception $e) {
270 $generator =
new RequirementPasswordGenerator();
271 $generator->setLength($this->config->min_password_length);
274 $lower = $this->config->min_password_lower;
276 $lower = (int) $lower;
278 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_LOWER_CASE,
false);
280 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_LOWER_CASE,
true);
281 $generator->setMinimumCount(RequirementPasswordGenerator::OPTION_LOWER_CASE, $lower);
286 $upper = $this->config->min_password_upper;
288 $upper = (int) $upper;
290 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_UPPER_CASE,
false);
292 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_UPPER_CASE,
true);
293 $generator->setMinimumCount(RequirementPasswordGenerator::OPTION_UPPER_CASE, $upper);
298 $number = $this->config->min_password_number;
300 $number = (int) $number;
301 if (empty($number)) {
302 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_NUMBERS,
false);
304 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_NUMBERS,
true);
305 $generator->setMinimumCount(RequirementPasswordGenerator::OPTION_NUMBERS, $number);
310 $special = $this->config->min_password_special;
312 $special = (int) $special;
313 if (empty($special)) {
314 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_SYMBOLS,
false);
316 $generator->setOptionValue(RequirementPasswordGenerator::OPTION_SYMBOLS,
true);
317 $generator->setMinimumCount(RequirementPasswordGenerator::OPTION_SYMBOLS, $special);
332 $min_length = (int) $this->config->min_password_length;
334 $requirements_length = (
int) $this->config->min_password_lower;
335 $requirements_length += (int) $this->config->min_password_upper;
336 $requirements_length += (
int) $this->config->min_password_number;
337 $requirements_length += (int) $this->config->min_password_special;
339 return max($min_length, $requirements_length, $length);
350 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.
__construct(protected Config $config, protected Translator $translator, protected EventsService $events)
Constructor.
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.
$config
Advanced site settings, debugging section.
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.
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.