PHP validate password

Asked

Viewed 102 times

-3

I don’t have great bases with PHP however, I need to do validations like:

  • string size
  • contains letters, uppercase and minuscule
  • contains numbers
  • contain 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 some special character. What would be the best way to check all this.

Thanks in advance!

1 answer

1


The expression below encompasses at least one minuscule letter, uppercase, 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);

Read this answer while you’re at it. It’s pretty cool and clears up a few things: https://stackoverflow.com/a/48346033/7437072

if someone translated I would "upvotaria" because it is very detailed

Browser other questions tagged

You are not signed in. Login or sign up in order to post.