Created
March 4, 2014 03:01
-
-
Save bmcculley/9339529 to your computer and use it in GitHub Desktop.
Check for password strength, password should be at least n characters, contain at least one number, contain at least one lowercase letter, contain at least one uppercase letter, contain at least one special character.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$password_length = 8; | |
function password_strength($password) { | |
$returnVal = True; | |
if ( strlen($password) < $password_length ) { | |
$returnVal = False; | |
} | |
if ( !preg_match("#[0-9]+#", $password) ) { | |
$returnVal = False; | |
} | |
if ( !preg_match("#[a-z]+#", $password) ) { | |
$returnVal = False; | |
} | |
if ( !preg_match("#[A-Z]+#", $password) ) { | |
$returnVal = False; | |
} | |
if ( !preg_match("/[\'^£$%&*()}{@#~?><>,|=_+!-]/", $password) ) { | |
$returnVal = False; | |
} | |
return $returnVal; | |
} | |
?> |
It must contain between 8 and 32 characters. Use only characters from the following set: ! # $ % & ( ) * + , - . / 0123456789 : ; < = > ? @ ABCDEFGHIJKLMNOPQRSTUVWXYZ [ \ ] _ ` abcdefghijklmnopqrstuvwxyz { | } ~
It must contain at least 1 capital letter(s) (ABCDEFGHIJKLMNOPQRSTUVWXYZ).
It must contain at least 1 numeric character(s) (0123456789).
It must not contain more than 2 identical consecutive characters (AAA, iiii, $$$$$ ...).
It must not contain your user name.
It must not contain your email address.
It must not contain your first name.
It must not contain your last name
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great , code work for me 👍