Challenge 65

Description

The purpose of this challenge is load a tokenized file. This challenge simulates a login system.

 Requirements

  1. Using vi, create a text file, bbcreds.txt, that will contain the following data as shown below. You don’t have to write code to create this file.  The 4 columns in this file are: username, password, enabled/disabled, password age. You will need to create the appropriately-typed tokens for each of these columns
    walter The1WhoKnocks 1 125
    jesse CapnCook 1 30
    saul wasMcGill 0 60
    hank DEAdman 1 7
    gus p0ll0fring0 1 99
    
  2. Write a function int validate(string username, string password). This function will:
    1. Open the file bbcreds.txt and read the tokens in the file
    2. Compare username and password parameters against the credentials in the file
    3. If the username and password match the account info in the file, then return the fourth column (password age). Otherwise,
      1. If the user account is disabled (third column is 0), then return -3
      2. If the username parameter is not found in the file, then return -2. Understand that you will have to have compared username to ALL the username tokens from the file before it can be determined that username is not in the file.
      3. If the password parameter doesn’t match the password in the file but the username is correct, then return -1
  3. In main(),
    1. Ask the user for login and password information (see Sample Interaction)
    2. Call the validate() function. Display an appropriate message based on its return value. See Sample Interaction. If the function returns a non-negative value, this number represents the password age. If this age value is greater than 120, display an appropriate message (See Interaction). If the username is found but the password is wrong, repeat the prompt up to 3 times total.

Sample main()

int main()
{
  string username;
  string password;
  
  cout << "Login: ";
  cin >> username;

  cout << "Password: ";
  cin >> password;

  // use the validate() function call to validate credentials
  // use the return value of validate() to:
  //   - display a message if the user is not found
  //   - display a message if the credentials are invalid. 
  //     Only allow the user to attempt login 3 times. 
  //     If credentials are still invalid after three 
  //     attempts, stop prompting for user info
  //   - display a message if the user's account is disabled
  // If the user successfully validates their credentials, 
  // display a message if the user needs to change 
  // their password

  return 0;
}

Sample Interaction

Login: hank
Password: DEAdman 

Login successful
Login: hank 
Password: deadman 
Access Denied

Password: DeadMan 
Access Denied

Password: abc123 
Access Denied

Login failed - maximum attempts
Login: saul 
Password: wasMcGill 
saul account is disabled
Login: badger 
Password: HeyHey 
badger account does not exist
Login: walter 
Password: The1WhoKnocks 

Login successful
walter, your password is 125 days old. Please change.

LEGEND
PROGRAM OUTPUT
USER INPUT
FROM INPUT

CATALOG ID: CPP-CHAL0065

Print Requirements