Passwords are very important security matters. How can the web developer be sure, that some security guidelines were implemented when passwords are set? Here is a password validation function, that might be useful:
public function isValidPasswordMsg($pwd)
{
$error = "";
if( strlen($pwd) < 6 ) {
$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(empty($error))
return TRUE;
return $error;
}
The above function uses the php regular expressions function which is very useful in this situations.
public function isValidPasswordMsg($pwd)
{
$error = "";
if( strlen($pwd) < 6 ) {
$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(empty($error))
return TRUE;
return $error;
}
The above function uses the php regular expressions function which is very useful in this situations.
Posting Komentar