Return array of error messages on password validate
This commit is contained in:
parent
5bb863ffc9
commit
e18b649250
|
@ -230,22 +230,28 @@ final class MD_STD_IN {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates a password (minimum requirements: 8 characters, including
|
* Validates a password (minimum requirements: 8 characters, including
|
||||||
* one number and one special char).
|
* one number and one special char) and returns a list of errors,
|
||||||
|
* if there are any.
|
||||||
*
|
*
|
||||||
* @param string $input Input string.
|
* @param string $input Input string.
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return array<string>
|
||||||
*/
|
*/
|
||||||
public static function validate_password(string $input):bool {
|
public static function validate_password(string $input):array {
|
||||||
|
|
||||||
|
$errors = [];
|
||||||
if (mb_strlen($input) < 8) {
|
if (mb_strlen($input) < 8) {
|
||||||
return false;
|
$errors[] = 'password_too_short';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((\preg_match('@[0-9]@', $input)) === false) return false;
|
if ((\preg_match('@[0-9]@', $input)) === false) {
|
||||||
if ((\preg_match('@[^\w]@', $input)) === false) return false;
|
$errors[] = 'password_has_no_number';
|
||||||
|
}
|
||||||
|
if ((\preg_match('@[^\w]@', $input)) === false) {
|
||||||
|
$errors[] = 'password_has_no_special_char';
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return $errors;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user