PHP validate password

-3

I do not have large bases with PHP however, I need to do validations like:

  • string size
  • contains upper and lower case letters
  • contains numbers
  • contains special characters

In this case for a password, I tried to do with regex, however I do not know how I can check if it has any special character. What would be the best way to check all this.

Thank you in advance!

    
asked by anonymous 14.12.2018 / 18:55

1 answer

1

The expression below includes at least one lower case, upper case, number and symbol. with a size of 8+ chars:

preg_match('/^(?=\P{Ll}*\p{Ll})(?=\P{Lu}*\p{Lu})(?=\P{N}*\p{N})(?=[\p{L}\p{N}]*[^\p{L}\p{N}])[\s\S]{8,}$/', $entrada, $saida);

Enjoy and read this answer. It's pretty cool and clarifies some things: link

If someone translated "upvariation" because it is very detailed

    
14.12.2018 / 19:02