Hello, I need to write a password check function to validate the following:

  1. Length of the string is at least 5 characters.
  2. Cannot be all digits.
  3. Cannot contain a space.

Below is some of what I have so far but I'm not sure if it is correct. Any suggestions is greatly appreciated.

void CheckPassword(cin, s)
{
     password = CheckPassword();

     do 
    {
         cout << "password: ";
         getline(cin, s);
         }

     if (length < 5 ) 
     {
         cout << "password: ";

Do you have to use c strings or can you use c++ strings?

Here you have both references (c-style strings and c++ strings)

http://www.cplusplus.com/reference/clibrary/cstring/
http://www.cplusplus.com/reference/string/string/

For the 1st problem, use the lenght function.
2nd, check the string character by character until
A) You find a non digit (correct)
B) The string ends (Incorrect password, all digits)
(You must compare the ASCII codes)

3rd. Same thing, but check the entire string for a space.

Remember you need to enclose your code in quote tags.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.