Ok so my friend bet me that I couldn't write a user login program so I am trying to but I am having trouble with getting a certain line to change if the user wants to change his/her password here is my code:
#include <iostream>
#include <string>
using namespace std;
int main() {
string a;
string b;
string a1 = "Jacob";
string b1 = "Password";
string pass;
unsigned short t = 0;
char p;
if (a == a1 && b == b1) {
t = 0;
cout << "Welcome, would you like to change your password? [y/n]\n";
cin.ignore(1000, '\n');
cin >> p;
break;
} else {
cout << "YOU ARE A FAIL ~c==3\n" << "TRY AGAIN\n";
++t;
cin.ignore(1000, '\n');
}
}
if (t == 3){
cout << "EXITING PRESS ENTER";
cin.get();
exit(0);
}
if (p == 'y') {
cout << "Cannot change password\n"; //This is what it says for now want
//it to change b1 to what user wants
} else if (p == 'n') {
cout << "Thank you, goodbye\n";
}
Although it is possible to do what you want, it is very difficult. It involves modifying the executable. The simpler solution would be to store the password in a separate file.
I think that this is a function you can perform on a simple while loop. Or you can call a separate function when the user types in a letter into the console.
This is really helpful if you are designing a system that would require passwords. Though, I had some problem with it when the program was taking the backspace as a letter and not used to erase the already typed in letter. I guess a regular expression would do the trick.