943,724 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 837
  • PHP RSS
Jul 1st, 2009
0

Passsword Strength Checker

Expand Post »
Passsword Strength Checker

php Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3.  
  4. function testPassword($password)
  5. {
  6. if ( strlen( $password ) == 0 )
  7. {
  8. return 1;
  9. }
  10.  
  11. $strength = 0;
  12.  
  13. /*** get the length of the password ***/
  14. $length = strlen($password);
  15.  
  16. /*** check if password is not all lower case ***/
  17. if(strtolower($password) != $password)
  18. {
  19. $strength += 1;
  20. }
  21.  
  22. /*** check if password is not all upper case ***/
  23. if(strtoupper($password) == $password)
  24. {
  25. $strength += 1;
  26. }
  27.  
  28. /*** check string length is 8 -15 chars ***/
  29. if($length >= 8 && $length <= 15)
  30. {
  31. $strength += 1;
  32. }
  33.  
  34. /*** check if lenth is 16 - 35 chars ***/
  35. if($length >= 16 && $length <=35)
  36. {
  37. $strength += 2;
  38. }
  39.  
  40. /*** check if length greater than 35 chars ***/
  41. if($length > 35)
  42. {
  43. $strength += 3;
  44. }
  45.  
  46. /*** get the numbers in the password ***/
  47. preg_match_all('/[0-9]/', $password, $numbers);
  48. $strength += count($numbers[0]);
  49.  
  50. /*** check for special chars ***/
  51. preg_match_all('/[|!@#$%&*\/=?,;.:\-_+~^\\\]/', $password, $specialchars);
  52. $strength += sizeof($specialchars[0]);
  53.  
  54. /*** get the number of unique chars ***/
  55. $chars = str_split($password);
  56. $num_unique_chars = sizeof( array_unique($chars) );
  57. $strength += $num_unique_chars * 2;
  58.  
  59. /*** strength is a number 1-10; ***/
  60. $strength = $strength > 99 ? 99 : $strength;
  61. $strength = floor($strength / 10 + 1);
  62.  
  63. return $strength;
  64. }
  65.  
  66. /*** example usage ***/
  67. $password = 'qwer1234';
  68. echo testPassword($password);
  69.  
  70. ?>
Similar Threads
Reputation Points: 17
Solved Threads: 6
Posting Pro in Training
ayesha789 is offline Offline
485 posts
since Jun 2009
Jul 1st, 2009
0

Re: Passsword Strength Checker

Hey, will this give you a password strength instantly?, because I thought php would be run on the server side. If that's the case, is it possible to have a client_side code maybe in 'javascript' that gives instant password strength?
Thanks for your input anyway!
Reputation Points: 13
Solved Threads: 0
Newbie Poster
webish is offline Offline
9 posts
since Jun 2009
Jul 1st, 2009
0

Re: Passsword Strength Checker

No, Its gives strengths from the server. if u have javascript code please share with all.

Ayesha
Reputation Points: 17
Solved Threads: 6
Posting Pro in Training
ayesha789 is offline Offline
485 posts
since Jun 2009
Jul 1st, 2009
3

Re: Passsword Strength Checker

Here is an interesting page that could be used to create a password strength meter:

http://www.lockdown.co.uk/?pg=combi
Moderator
Reputation Points: 457
Solved Threads: 101
Nearly a Posting Virtuoso
digital-ether is offline Offline
1,250 posts
since Sep 2005
Jul 2nd, 2009
0

Re: Passsword Strength Checker

Thanks Digital-ether
Reputation Points: 17
Solved Threads: 6
Posting Pro in Training
ayesha789 is offline Offline
485 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Save a webpage?
Next Thread in PHP Forum Timeline: Gallery Alignment?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC