Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enforcing Password Requirements

I want to check if the user has successfully met the following requirements:

  • The password has at least 8 characters
  • Consists of one capital & one lowercase letter

How would I do this?

I am using the PHP script below:

if ( strlen( $password ) < 8 ) {
     false
} else {
   if ( preg_match( "/[^0,9]/", $password ) ) {
     // how to check the upper case and lower case
   }
}
like image 791
Glen Mongaya Avatar asked May 31 '11 03:05

Glen Mongaya


People also ask

What is enforce password?

The Enforce password history policy setting determines the number of unique new passwords that must be associated with a user account before an old password can be reused. Password reuse is an important concern in any organization.

Why is it important to enforce password complexity policy?

In theory, the main benefit of password complexity rules is that they enforce the use of unique passwords that are harder to crack. The more requirements you enforce, the higher the number of possible combinations of letters, numbers, and characters.

What requirements should be enforced on passwords chosen by employees?

Password creation Employees should choose passwords that are at least eight characters long and contain a combination of upper- and lower-case letters, numbers, and punctuation marks and other special characters. These requirements will be enforced with software when possible.


1 Answers

You can do that with a regex:

if (!preg_match('/^(?=[a-z])(?=[A-Z])[a-zA-Z]{8,}$/', $password))
{
    //error
}
like image 70
John Conde Avatar answered Oct 15 '22 18:10

John Conde