1
Answer

How to write the function to check the password?

Richa Garg

Richa Garg

12y
1.7k
1
If I want to write the function to check the password entered is correct or not based on the following conditions,how can i write it?
1) It must have atleast one lower case character and one digit.
2) It must not have any upper case character and one digit.
3) Length should be between 5-12
4) It should not have any same immediate pattern like,
  -> abcanan1 : not acceptable , because of an pattern a.
  -> abc11se : not acceptable , because of 11.
  -> 123sd123 : acceptable , as not immediate pattern.
  -> adfasdsdf : not acceptable , as no digits.
  -> Aasdfasd12 : not acceptable, as have uppercase character.

Please help to to write this function.
Answers (1)
0
Sivaraman Dhamodaran
NA 61.8k 2.7m 12y
Well. You don't have any special char need in your spec.

Define a strings like:
"abcdefghijklmnopqrstuvwxyz0123456789".
"abcdefghijklmnopqrstuvwxyz"
" 0123456789"
Have a boolean flag for each.
Algo:
1) Iterate through each pwd char. Make sure the char falls in above string. When char not found, set the flag to false. When a char is lower case letter set the relevant flag to true. When a char is digit set flag related to digit as true. At the end of iteration you can check the flags to satisfy first three points.
2) For fourth point you need a inner loop that again iterates through all your chars. Here you can check the repeatable patterns.