Tuesday, 3 July 2012

Creating a Strong password having character,letter,speical symbol 1 each

$pwd = "Vijay((#@!99321";

if( strlen($pwd) < 8 ) {
 $error .= "Password too short! <br />";
}

if( strlen($pwd) > 20 ) {
 $error .= "Password too long! <br />";
}

if( strlen($pwd) < 8 ) {
 $error .= "Password too short! <br />";
}

if( !preg_match("#[0-9]+#", $pwd) ) {
 $error .= "Password must include at least one number! <br />";
}


if( !preg_match("#[a-z]+#", $pwd) ) {
 $error .= "Password must include at least one letter! <br />";
}


if( !preg_match("#[A-Z]+#", $pwd) ) {
 $error .= "Password must include at least one CAPS! <br />";
}



if( !preg_match("#\W+#", $pwd) ) {
 $error .= "Password must include at least one symbol! <br />";
}


if($error){
 echo "Password validation failure(your choise is weak): $error";
} else {
 echo "Your password is strong.";
}
 
 

Putting all together:

 
$pwd = "Vijay((#@!99321";

if (preg_match("#.*^(?=.{8,20})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\W).*$#", $pwd)){
    echo "Your password is strong.";
} else {
    echo "Your password is not safe.";
} 
 

Password with number,letter,caps:

 
$pwd = "Vijay99321";
 
 
 if (preg_match("#.*^(?=.{8,20})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).*$#", $pwd)){
    echo "Your password is good.";
} else {
    echo "Your password is bad.";
} 
 
 

No comments:

Post a Comment