Jump to content

[SOLVED] Question Validating Password


TTMP

Recommended Posts

First I would like to say hi to everyone here and ask the experts to please give me some guidance with this issue I'm having validating a password.

I have googled this and tried every possible but for some reason nothing seems to work the right way.

 

What I need is the password can be in any order but has to have these requirements:

Minimum of 8 characters.

Maximum of 20 characters.

At least one lower case letter.

At least one upper case letter.

At least one number.

And at least one of these ~!@#$%^&*()_+ special characters.

 

I have tried many solutions for this and everytime it allows passwords that do not meet these requirements.

 

If someone could help me with this I would really appreciate it.

 

Thank you in advance.

Link to comment
https://forums.phpfreaks.com/topic/83608-solved-question-validating-password/
Share on other sites

Hi,

 

For the 8-20 character limit you can use a simple length comparison.

 

For the lower and upper case letters, you can convert the password string using one of php's functions into an all lowercase form. If this form equals the original, then you know that the user did not enter any uppercase letters. You can use another function to convert it to an all uppercase form. I think these functions are strtoupper() and strtolower().

 

For the numbers and special characters, you can use a simple regular expression.

 

Hope this helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.