Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a C++ class which, when fed a username and password, can validate that th

ID: 3766023 • Letter: C

Question

Create a C++ class which, when fed a username and password, can validate that the username and password meets the following criteria:

The username should:

- have at least 8 characters long
- contains only alpha numeric characters (no spaces or special characters)
- contain at least 1 uppercase character
- contain at least 1 lowercase character
- contain at least 1 numeric character (0-9)

The password should:

- not contain a user’s username (i.e. the username “CraigKapp1? is valid, but if that user has the password “CraigKapp1Password”, this password would not be valid because it contains the string “CraigKapp1?)
- be at least 8 characters long
- only contain alpha numeric characters (no spaces or special characters)
- contain at least 1 uppercase character
- contain at least 1 lowercase character
- contain at least 1 numeric character (0-9)

HINT: For this assignment, a very useful library of helper functions are available when you say:   

A number of different program dialogues describe the program I am looking for.

CS52 Username/Password Validator
Username: SmcCorsair1
Password: GoDodgers1
The Username/Password combination is valid!

CS52 Username/Password Validator
Username: SmcCorsair
Password: GoDodgers1
The Username requires numeric character

CS52 Username/Password Validator
Username: smccorsair1
Password: GoDodgers1
The Username requires an uppercase character

CS52 Username/Password Validator
Username: SMCCORSAIR1
Password: GoDodgers1
The Username requires an lowercase character

CS52 Username/Password Validator
Username: corsair
Password: GoDodgers1
The Username requires atleast 8 letters

CS52 Username/Password Validator
Username: SmcCorsair1
Password: aaSmcCorsair1aa
The Password cannot contain the Username

CS52 Username/Password Validator
Username: SmcCorsair1
Password: gododgers1
The Password requires an uppercase character

CS52 Username/Password Validator
Username: SmcCorsair1
Password: GODODGERS1
The Password requires an lowercase character

CS52 Username/Password Validator
Username: SmcCorsair1
Password: Smc1
The Password requires atleast 8 letters

Explanation / Answer

.

-

asked May 24 at 6:32

Ryan
82

1

Btw., the return 0; cin.get(); in the if block makes no sense. A return is the end of the whole function, the cin.get(); won´t get executed. – May 24 at 6:41

  

Yeah, I think that got left behind from early stages or something. Thanks for pointing it out though. I could definitely use to get in to the habit of going back and cleaning up after myself. – Ryan May 25 at 7:12

Your username includes a newline character ' ' after the first attempt due to getline

Changing your cin usage from

to

  #include <iostream>  
  #include <string>  
       
  using namespace std;  
       
  int main()  
  {  
      int attempts=0;  
      string username, password;  
      while (attempts < 3)  
      {  
          cout<<" Please enter your username and password seperated by a space. ";  
          getline( cin, username, ' ');  
          cin>>password;  
          if (username == "Ryan" && password == "pass")  
          {  
              cout<<" You have been granted access.";  
              return 0;  
              cin.get();  
          }  
          else  
          {  
              attempts++;  
              //cout<<username <<" " <<password << " ";  
              cout<<"Incorrect username or password, try again.";  
              cout<<" Attempts remaining: "<<3-attempts <<" ";  
          }  
      }  
      cout<<" Out of attempts, access denied.";  
      cin.get();  
       
  }  

.

-

asked May 24 at 6:32

Ryan
82

1

Btw., the return 0; cin.get(); in the if block makes no sense. A return is the end of the whole function, the cin.get(); won´t get executed. – May 24 at 6:41

  

Yeah, I think that got left behind from early stages or something. Thanks for pointing it out though. I could definitely use to get in to the habit of going back and cleaning up after myself. – Ryan May 25 at 7:12