Results 1 to 4 of 4

Thread: [PHP] Check Password Strength

  1. #1

    Thread Starter
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    [PHP] Check Password Strength

    Checks the strength of a password and return an integer value depening on it's strength

    PHP Code:
    function CheckPasswordStrength($password)
    {
        
        
    $strength 0;
        
    $patterns = array('#[a-z]#','#[A-Z]#','#[0-9]#','/[¬!"£$%^&*()`{}\[\]:@~;\'#<>?,.\/\\-=_+\|]/');
        foreach(
    $patterns as $pattern)
        {
            if(
    preg_match($pattern,$password,$matches))
            {
                
    $strength++;
            }
        }
        return 
    $strength;
        
        
    // 1 - weak
        // 2 - not weak
        // 3 - acceptable
        // 4 - strong
    }

    //usage
    CheckPasswordStrength('password'); //1
    CheckPasswordStrength('Password'); //2
    CheckPasswordStrength('P4ssword'); //3
    CheckPasswordStrength('P4ssw()rd'); //4 

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [PHP] Check Password Strength

    Nice, nice... might use a variation on this, thanks for the idea!

  3. #3
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: [PHP] Check Password Strength

    Thanks for this! i am going to use this function in a Authentication class i am going to use.

    Will give credit

    My usual boring signature: Something

  4. #4
    New Member
    Join Date
    Aug 2016
    Posts
    1

    Re: [PHP] Check Password Strength

    Thanks for sharing but I can't get this to work. Is there an update for the code?
    Last edited by DeePop; Dec 7th, 2023 at 04:19 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width