Passsword Strength Checker

Thread Solved

Join Date: Jun 2009
Posts: 219
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training

Passsword Strength Checker

 
0
  #1
Jul 1st, 2009
Passsword Strength Checker

  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. ?>
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 9
Reputation: webish is an unknown quantity at this point 
Solved Threads: 0
webish webish is offline Offline
Newbie Poster

Re: Passsword Strength Checker

 
0
  #2
Jul 1st, 2009
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!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 219
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training

Re: Passsword Strength Checker

 
0
  #3
Jul 1st, 2009
No, Its gives strengths from the server. if u have javascript code please share with all.

Ayesha
Ayesha
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,082
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Passsword Strength Checker

 
3
  #4
Jul 1st, 2009
Here is an interesting page that could be used to create a password strength meter:

http://www.lockdown.co.uk/?pg=combi
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 219
Reputation: ayesha789 is an unknown quantity at this point 
Solved Threads: 3
ayesha789's Avatar
ayesha789 ayesha789 is offline Offline
Posting Whiz in Training

Re: Passsword Strength Checker

 
0
  #5
Jul 2nd, 2009
Thanks Digital-ether
Ayesha
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC