• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MeNeedz Password

#19
[eluser]Pinkiee[/eluser]
The code below is for demonstration only.
I am new to CI, and I have not read up on the conventions
I also have not tested the code below
I am aware that there are still better ways to do this.
There is a large lack of comments
etc.

But I think it displays what I was saying.

One for loop, no arrays, no if statements that are not needed.

I really do think that this is a great idea, and I would love to see it turned into a library where you can "tweak" the values etc. I might even get around to it myself one day.

Code:
function check_strength($password)
    {
        
        $password_length = strlen($password);
        if ($password_length > 0)
        {
            // Length
            if ($password_length > 0)
            {
                $_points += 5;
                
                if($password_length >= 5)
                {
                    $_points += 5;
                    
                    if($password_length >= 7)
                    {
                        $_points += 15;
                    }
                }
            }
            
            
            // gather the information
            foreach ($password as $character)
            {
                if (ctype_lower($character))
                {
                    $lower_case_count++;
                }
                else if (ctype_upper($character))
                {
                    $upper_case_count++;
                }
                else if (ctype_digit($character))
                {
                    $numeric_count++
                }
                else if (ctype_punct($character))
                {
                    $special_count++;
                }
            }
            
            if($lower_case_count > 0)
            {
                $_points += 10;
            }
    
            if($upper_case_count > 0)
            {
                $_points += 10;
            }
            
            // numeric
            if($numeric_count > 0)
            {
                if ($numeric_count <= 2)
                {
                    $_points += 10;
                }
                else
                {
                    $_points += 20;
                }
            }

            // special characters
            if ($special_count > 0)
            {
                if ($special_count == 1)
                {
                    $_points += 10;
                }
                else
                {
                    $_points += 25;
                }
            }
            
            // bonus - note you were "double checking" values you had already checked
            // this does not give a bonus for jsut having both lower and upper
            // nor for lower AND upper AND numeric
            // I have not changed it though as this may be by design
            if($numeric_count > 0 AND ($lower_case_count > 0 OR $upper_case_count > 0))
            {
                $_points += 2;
                if($special_count > 0)
                {
                    $_points += 1;
                    if($lower_case_count > 0 AND $upper_case_count > 0)
                    {
                        $_points += 2;
                    }
                }
            }
            
        }
        
        return $_points;
        
    }


Messages In This Thread
MeNeedz Password - by El Forum - 01-02-2009, 04:28 AM
MeNeedz Password - by El Forum - 01-04-2009, 04:51 AM
MeNeedz Password - by El Forum - 01-04-2009, 10:17 AM
MeNeedz Password - by El Forum - 01-04-2009, 11:08 AM
MeNeedz Password - by El Forum - 01-04-2009, 12:16 PM
MeNeedz Password - by El Forum - 01-04-2009, 02:41 PM
MeNeedz Password - by El Forum - 01-04-2009, 10:13 PM
MeNeedz Password - by El Forum - 01-05-2009, 03:01 AM
MeNeedz Password - by El Forum - 01-05-2009, 12:13 PM
MeNeedz Password - by El Forum - 01-05-2009, 12:26 PM
MeNeedz Password - by El Forum - 01-05-2009, 01:08 PM
MeNeedz Password - by El Forum - 01-05-2009, 01:15 PM
MeNeedz Password - by El Forum - 01-05-2009, 02:34 PM
MeNeedz Password - by El Forum - 01-05-2009, 02:45 PM
MeNeedz Password - by El Forum - 01-05-2009, 02:52 PM
MeNeedz Password - by El Forum - 01-23-2009, 11:01 PM
MeNeedz Password - by El Forum - 06-30-2009, 06:38 PM
MeNeedz Password - by El Forum - 07-01-2009, 01:36 AM
MeNeedz Password - by El Forum - 07-01-2009, 07:10 PM
MeNeedz Password - by El Forum - 07-02-2009, 02:03 AM
MeNeedz Password - by El Forum - 07-02-2009, 06:28 AM
MeNeedz Password - by El Forum - 07-02-2009, 06:29 AM
MeNeedz Password - by El Forum - 07-02-2009, 07:03 AM
MeNeedz Password - by El Forum - 07-02-2009, 09:00 AM
MeNeedz Password - by El Forum - 07-02-2009, 09:36 AM
MeNeedz Password - by El Forum - 01-02-2010, 07:26 AM
MeNeedz Password - by El Forum - 01-02-2010, 07:35 AM
MeNeedz Password - by El Forum - 01-02-2010, 07:58 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.