Define username and password as array variables
In the program, set an initial value for the variables
The user should be able to login using the default credentials
The program should be able to change the default values of the array
If the user tries to login using wrong credentials he will be asked to re-login but after 3 wrong attempts the program will display "You've exceeded the allowable number of tries! Try again later"
If the user successfully logged in, the message "Welcome to my World" should be displayed on screen
If this can done in a user-define function, it would be better but not required for now.
SCREEN LAYOUT / DESIGN
(prompt 1)
Username: default
Password: admin
Change Username and Password
[Y/N]: Y
(prompt 2)
Username: correct UN
Password: correct PW
Welcome to my World
(prompt 3)
Username: wrong UN
Password: wrong PW
(for the 3rd time)
You've exceeded the allowable number of tries! Try again later
#include<iostream>
#include <string.h>
using namespace std;
int main(){
char username [20] = {"default"};
char password [20] = {"admin"};
char pass[20];
char user[20];
cout<<"Username: default\nPassword: admin\n";
cout<<"Change Username and Password\n[Y/N]: ";
char y ;
cin>>y;
if(y=='Y'){
cout<<"Enter username\n";
cin>>user;
cout<<"Enter password\n";
cin>>pass;
}
for(int x=0; x<20; x++){
username[x] = user[x];
password[x] = pass[x];
}
int i = 1;
while(i<=4){
cout<<"Enter username: ";
char entered_user[20];
cin>>entered_user;
char entered_password[20];
cout<<"Enter password: ";
cin>>entered_password;
int res1 = strcmp(username, entered_user);
int res2 = strcmp(password, entered_password);
if(res1 ==0 && res2==0 ){
cout<<"Welcome to my World\n";
break;
}
else{
cout<<"Wrong Credentials\n";
}
if(i==3){
cout<<"You've exceeded the allowable number of tries! Try again later\n";
break;
}
i++;
}
}
Comments
Leave a comment