Return array of error messages on password validate

This commit is contained in:
Joshua Ramon Enslin 2022-03-08 21:23:45 +01:00
parent 5bb863ffc9
commit e18b649250
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

View File

@ -230,22 +230,28 @@ final class MD_STD_IN {
/**
* 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.
*
* @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) {
return false;
$errors[] = 'password_too_short';
}
if ((\preg_match('@[0-9]@', $input)) === false) return false;
if ((\preg_match('@[^\w]@', $input)) === false) return false;
if ((\preg_match('@[0-9]@', $input)) === false) {
$errors[] = 'password_has_no_number';
}
if ((\preg_match('@[^\w]@', $input)) === false) {
$errors[] = 'password_has_no_special_char';
}
return true;
return $errors;
}