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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.