パスワード確認スクリプトを作成しようとしています。次のようなメール(許可されていない文字)のチェックが既にあります。
public function checkEmail($email)
{
if (filter_var($email, FILTER_VALIDATE_EMAIL))
return true;
else
return false;
}
そこで、パスワードに少なくとも1文字の英数字、1文字の数字、最低8文字が含まれていることを確認し、エラーメッセージを表示するパスワード検証機能を探しています。
public function checkPassword($pwd, &$errors) {
$errors_init = $errors;
if (strlen($pwd) < 8) {
$errors[] = "Password too short!";
}
if (!preg_match("#[0-9]+#", $pwd)) {
$errors[] = "Password must include at least one number!";
}
if (!preg_match("#[a-zA-Z]+#", $pwd)) {
$errors[] = "Password must include at least one letter!";
}
return ($errors == $errors_init);
}
これの編集バージョン: http://www.cafewebmaster.com/check-password-strength-safety-php-and-regex