I am learning php on my own. I am creating a new user register page using php/mysql. I want to make sure that the password entered by user in condition specific, that is, must contain one upper case letter, one number and 开发者_如何学编程one special character. Any suggestions?
Use a regular expression to test the password against.
One (of many) ways to do this:
function check_password($text)
{
$regex = "#.*^(?=.{8,20})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\W).*$#"
if (preg_match($regex, $text)) {
return TRUE;
}
else {
return FALSE;
}
}
Also see: http://www.cafewebmaster.com/check-password-strength-safety-php-and-regex
Try this & look up Regular Expression
function check_password($password){
if (preg_match('/^[A-Z]+$/', $password)) {
if (preg_match('/^[0-9]+$/', $password)) {
if (preg_match('/^[*\+?{}.]+$/', $password)) {
return true;
}
}
}else{
return false;
}
}
精彩评论