Skip to content

Instantly share code, notes, and snippets.

@bmcculley
Created March 4, 2014 03:01
Show Gist options
  • Save bmcculley/9339529 to your computer and use it in GitHub Desktop.
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.
<?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;
}
?>
@redsparkers
Copy link

redsparkers commented Feb 15, 2018

great , code work for me 👍

@fooziya
Copy link

fooziya commented May 5, 2019

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