Click to See Complete Forum and Search --> : implementing password complexity
rahul_p
September 13th, 2006, 02:27 AM
hi.initially i presented my question in the form of a code.to put it more precisely,this is what i want:
password:
* Must be at least 6 characters and utmost 12 characters
* Must contain at least one one lower case letter, one upper case letter, one digit and one special character
* Valid special characters are - @#$%^&+=
thank u and sorry for posting twice.
kumaresh_ana
September 13th, 2006, 04:00 AM
Which platform and compiler you are using? If I am not wrong in .NET you could do that without wrinting any piece of code by setting the properties of the control.
But, there is no way you could do that without parsing the input by yourself and check for validity of each character the string has.
ps: do not cross post. You could have posted this in the previous thread you created.
rahul_p
September 13th, 2006, 05:13 AM
hi.i apologise once again for cross posting.well,my platform is Linux and the compiler is gcc.
i have done the parsing.i m just confused how to start of with code(how to define the functions etc...).any help wud be greatly appreciated.
kumaresh_ana
September 13th, 2006, 05:30 AM
Do you need to make the code more sophisticated so that even if the constraints changes there is not much work? I do not get your requirements.
NMTop40
September 13th, 2006, 05:46 AM
* Must be at least 6 characters and utmost 12 characters
str.size() >=6 && str.size() <= 12;
* Must contain at least one one lower case letter, one upper case letter, one digit and one special character
* Valid special characters are - @#$%^&+=
const char lowercase_chars[] = "abcdefghijklmnopqrstuvwxyz";
const char uppercase_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWYXYZ";
const char digits[] = "0123456789";
const char special_chars = "-@#$%^&+=";
str.find_first_of( lowercase_chars ) != std::string::npos;
str.find_first_of( uppercase_chars ) != std::string::npos;
str.find_first_of( digits ) != std::string::npos;
str.find_first_of( special_chars ) != std::string::npos;
btw, is the password allowed to contain other characters as well? You haven't said it isn't.
If not, then concatenate all those together and use find_first_not_of and check that is equal to npos. You can concatenate them by creating a string from one of them then using operator+.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.