Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<string>
- using namespace std;
- void login()
- {
- char npass[10];
- int i = 0;
- char user[10], name[10], newpass[10], oldpass[10];
- cout << "Enter user name: ";
- cin >> user;
- cout << "Enter password: ";
- ifstream file ("password.txt");
- if (file.is_open())
- {
- std::getline(file, name);
- std::getline(file, oldpass);
- if ((user == name) & (newpass == oldpass))
- cout << "Login successful!!!" << endl;
- else
- cout << "Wrong user name or password!!!" << endl;
- }
- cin.ignore();
- }
- int menu()
- {
- int opt;
- do{
- cout << "1: Login\n2: Exit\nEnter an option: ";
- cin >> opt;
- switch(opt)
- {
- case 1: login(); break;
- case 2: break;
- }
- }while(opt != 2);
- return 0;
- }
- void newuser()
- {
- char pass[10];
- int i = 0;
- char name[10];
- cout << "Welcome new user---" << endl
- << "Enter user name: ";
- cin >> name;
- cout << "Enter new password(6 characters): ";
- while(i < 6)
- {
- pass[i] = getch();
- cout << "*";
- i++;
- }
- cout << endl;
- ofstream file ("password.txt");
- file << name << endl;
- while (i < 6)
- {
- file << pass[i];
- i++;
- }
- file << '"' << endl;
- file.close();
- menu();
- }
- int main()
- {
- ifstream file ("password.txt");
- file.open ("password.txt");
- if (file.is_open())
- menu();
- else
- newuser();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement