Home » , » PHP Password validations using regexp

PHP Password validations using regexp

Written By Unknown on Minggu, 22 Desember 2013 | 08.47

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.
Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger