How to validate password strength in PHP

Today, we’ll explain to you how to validate password strength in PHP. It is very useful to check that the password is strong which protects the user accounts and prevents hacking.

Using regular expressions, we will validate the password strength in PHP.

Check the following points to validate the password strength

  • Password must be a minimum of 8 characters
  • Password must contain at least 1 number
  • Password must contain at least one uppercase character
  • Password must contain at least one lowercase character
  • Password must contain at least one special character

In the code below, we will use the PHP function preg_match() to check if the password matches the defined pattern.

Example

Let’s take an example to check the output. Use the above code with the HTML as below.

We can also check the password strength in a single pattern with regex.

Output

Run the code and check the output in the browser.

Output - How to validate password strength in PHP - Clue Mediator
Output – How to validate password strength in PHP – Clue Mediator

That’s it for today.
Thank you for reading. Happy Coding..!!

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

3 Responses

  1. Kazkzrdwah says:

    + for the post

  2. online pharmacies in usa says:

    Oh my goodness! Amazing article dude! Thanks, However I am encountering problems with your RSS. I don’t understand why I am unable to join it. Is there anybody else having the same RSS problems? Anyone that knows the solution will you kindly respond? Thanx!!

Leave a Reply

Your email address will not be published. Required fields are marked *