diff --git a/src/MD_STD_IN.php b/src/MD_STD_IN.php index 572ba7f..e0e0c83 100644 --- a/src/MD_STD_IN.php +++ b/src/MD_STD_IN.php @@ -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 */ - 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; }