tags:

views:

21

answers:

2

I need to validate a password it should have the following requirements:

  1. The password should have at least 8 characters
  2. The password should have at least 1 uppercase, 1 lowercase, 1 number, and 1 special character
  3. The password should have no continues character(ex. 12345 or abcd)

Please help me to do this.. any suggestions will be a big help. Thank you

A: 

Iterate string. If the character is uppercase then set bool isUppercase to true... If character is special character then set bool isSpecialCharacter to true. If the difference between this character and previous character is 1 then you have two consecutive characters, and you can stop iterating then (set bool haveConsecutiveCharacters to true).

The thing about consecutive characters is that if one of them is special character then they are not really consecutive (consider 'Z' and '[' that are next to each other in ASCII table).

After iterating check if all booleans are true and there are no consecutive characters.

Dialecticus
Thanks for your suggestions.
Mel
No need to thank me, I do it for points and glory :) I added one more note. If this is answer to your question consider marking it as answer.
Dialecticus
A: 

If you really want a regexp for this, you'll have to use assertions :

/^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[\W\D\S]).{8,}$/

Now, the hard part is no consecutive characters. I suggest doing it with a loop instead of doing it with a regexp (actually, I don't know how to do it with a regexp).

Vincent Savard