Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<string.h>
- using namespace std;
- string username;
- string password;
- struct user
- {
- string username;
- string password;
- };
- void registerUser(user);
- void login(user);
- int main()
- {
- user USER;
- int choice;
- cout << "Enter 1 to register or 2 to login: " << endl;
- cout << "Your choice: ";
- cin >> choice;
- if(choice == 1)
- registerUser(USER);
- else if(choice == 2)
- login(USER);
- }
- void registerUser(user USER)
- {
- ofstream outFile;
- outFile.open("Users Data.txt");
- cout << "Enter username: ";
- cin >> USER.username;
- cout << "Enter password: ";
- cin >> USER.password;
- outFile << "Username: " << USER.username << endl;
- outFile << "Password: " << USER.password << endl;
- outFile.close();
- }
- void login(user USER)
- {
- ifstream inFile;
- inFile.open("Users Data.txt");
- cout << "Enter your username: " ;
- cin>>username;
- cout << "Enter your password: " ;
- cin>>password;
- inFile>>USER.username>>USER.password;
- {
- if(username==USER.username)
- {
- if(password == USER.password)
- {
- cout << "Login successful!" << endl;
- }
- }
- else
- {
- cout << "Login error! Please try again. " << endl;
- }
- }
- inFile.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement