password strength checker

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    password strength checker

    after searching web for very simple, nice working php password checker i couldn't find any good solution for my needs,
    so i decided to code my own password strength checker,
    some function parts were taken from functions which ive found but they were not good enough for me.

    here is a function:

    PHP Code:
    function check_password_strength($password
    {
        
    $score = array("Blank","Very Weak","Weak","Medium","Strong","Very Strong");
        
    $strength password_strength_score($password);

        return 
    $score[$strength-1];
    }
    function 
    password_strength_score($password
    {
        
    $strength 0
        
        
    $length strlen($password);
        if (
    $length 1)
            return 
    1;
        elseif (
    $length 4)
            return 
    2;
        else 
    $strength 1;
        
        
    $clean_string preg_replace('/[^[:alnum:]]/i'''$password);
        
        if(
    strlen($clean_string) != $length$strength++;
        elseif(
    $length 5) return 2;
        
        if((
    $length strlen($clean_string))>1)
            
    $strength++;
        
        if (
    $length 7)
            
    $strength++;

        
        
    $patterns = array("#[a-z]#","#[A-Z]#","#[0-9]#");
        foreach(
    $patterns AS $pattern
        {
            if(
    preg_match($pattern,$password)) 
            { 
                
    $strength++; 
            } 
        }
        if(
    $strength>6)$strength=6;
        
        return 
    $strength;

    if someone has better functions please share here.
    Advertise your mobile site for FREE with AdTwirl


    #2
    iPhone post

    Checks the strength of a password and return an integer value depening on it's strength
    PHP Code:
    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'); 
    Creator of
    Epix.Mobi

    Keep an Eye on us Big things coming soon!!!!
    Need something for your site hit me up here

    http://coding-talk.com/forum/main-fo...r-your-wapsite

    Comment


      #3
      Originally posted by Loony View Post
      Checks the strength of a password and return an integer value depening on it's strength
      PHP Code:
      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'); 
      yes i saw this function, actually i took a small part from it.
      Advertise your mobile site for FREE with AdTwirl

      Comment


        #4
        [QUOTE=GumSlone;100854]after searching web for very simple, nice working php password checker i couldn't find any good solution for my needs,
        so i decided to code my own password strength checker,
        some function parts were taken from functions which ive found but they were not good enough for me.

        here is a function:

        PHP Code:
        $patterns = array('#[a-z]#','#[A-Z]#','#[0-9]#','/[¬!"£$%^&*()`{}\[\]:@~;\'#<>?,.\/\\-=_+\|]/'); 

        Comment


          #5
          Yeah I used parts for the 1 I made I'm not home ATM so I can't show you but I'll put it up asap for ya mate
          Creator of
          Epix.Mobi

          Keep an Eye on us Big things coming soon!!!!
          Need something for your site hit me up here

          http://coding-talk.com/forum/main-fo...r-your-wapsite

          Comment


            #6
            Originally posted by Anshul View Post
            PHP Code:
            $patterns = array('#[a-z]#','#[A-Z]#','#[0-9]#','/[¬!"£$%^&*()`{}\[\]:@~;\'#<>?,.\/\\-=_+\|]/'); 
            i have removed the last pattern and added some own code which checks if there are non alphanumeric symbols in the string, my code would work with symbols/chars like:
            üöансвкмцßв
            and not only with '/[¬!"£$%^&*()`{}\[\]:@~;\'#<>?,.\/\\-=_+\|]/'
            Advertise your mobile site for FREE with AdTwirl

            Comment


              #7
              PHP Code:
               <?php
              function checkPasswordStrength($password$username false)
              {
              $returns = array(
              'strength' => 0,
              'error'    => 0,
              'text'     => '');

              $length strlen($password);
                  if (
              $length 8)
                  {
                  
              $returns['error']    = 1;
                  
              $returns['text']     = 'The password is not long enough';
                  }
                      else
                      {
                      
              //check for a couple of bad passwords:
                      
              if ($username && strtolower($password) == strtolower($username))
                      {
                      
              $returns['error']    = 4;
                      
              $returns['text']     = 'Password cannot be the same as your Username';
                      }
                          elseif (
              strtolower($password) == 'password')
                          {
                          
              $returns['error']    = 3;
                          
              $returns['text']     = 'Password is too common';
                          }
                              else
                              {
                              
              preg_match_all ("/(.)\1{2}/"$password$matches);
                              
              $consecutives count($matches[0]);
                              
              preg_match_all ("/\d/i"$password$matches);
                              
              $numbers count($matches[0]);
                              
              preg_match_all ("/[A-Z]/"$password$matches);
                              
              $uppers count($matches[0]);
                              
              preg_match_all ("/[^A-z0-9]/"$password$matches);
                              
              $others count($matches[0]);
                                      
              //see if there are 3 consecutive chars (or more) and fail!
                                      
              if ($consecutives 0)
                                          {
                                          
              $returns['error']    = 2;
                                          
              $returns['text']     = 'Too many consecutive characters';
                                          }
                                              elseif (
              $others || ($uppers && $numbers 1))
                                              {
                                              
              //bulletproof
                                              
              $returns['strength'] = 5;
                                              
              $returns['text']     = 'Virtually Bulletproof';
                                              }
                                              elseif ((
              $uppers && $numbers 0) || $length 14)
                                              {
                                              
              //very strong
                                              
              $returns['strength'] = 4;
                                              
              $returns['text']     = 'Very Strong';
                                              }
                                          else if (
              $uppers || $numbers || $length 9)
                                          {
                                          
              //strong
                                          
              $returns['strength'] = 3;
                                          
              $returns['text']     = 'Strong';
                                          }
                                          else if (
              $numbers 1)
                                      {
                                      
              //fair
                                      
              $returns['strength'] = 2;
                                      
              $returns['text']     = 'Fair';
                                      }             
                                  else         
                                  {
                                  
              //weak
                                  
              $returns['strength'] = 1;
                                  
              $returns['text']     = 'Weak';
                                  }
                              }
                      }
              return 
              $returns;
              }
              ?>
              i've found this one, it doesn't look bad
              It's better to keep your mouth shut and give the impression that you're stupid, than to open it and remove all doubt.
              ⓣⓗⓔ ⓠⓤⓘⓔⓣⓔⓡ ⓨⓞⓤ ⓑⓔ©ⓞⓜⓔ, ⓣⓗⓔ ⓜⓞⓡⓔ ⓨⓞⓤ ⓐⓡⓔ ⓐⓑⓛⓔ ⓣⓞ ⓗⓔⓐⓡ !
              ιη тнєσяу, тнє ρяα¢тι¢є ιѕ α яєѕυℓт σƒ тнє тнєσяу, вυт ιη ρяα¢тι¢є ιѕ тнє σρρσѕιтє.
              キノgんイノ刀g 4 ア乇ムc乇 ノ丂 レノズ乇 キucズノ刀g 4 √ノ尺gノ刀ノイリ!

              Comment

              Working...
              X