Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string.h>
- #include <cstdlib>
- #include <stdlib.h>
- using namespace std;
- bool IsLoggedIn(){
- string Username, Password, un, pw;
- cout << "Enter your Username: ";
- cin >> Username;
- cout << "Enter your Password: ";
- cin >> Password;
- ifstream read("c:\\t" + Username + ".txt");
- getline(read, un);
- getline(read, pw);
- if(un == Username && pw == Password){
- return true;
- }
- else{
- return false;
- }
- }
- int main()
- {
- int choice;
- string file;
- cout << "1: Register\n2: Login\nYour Choice: "; cin >> choice;
- if(choice == 1){
- string Username, Password;
- cout << "Create a Username: ";
- cin >> Username;
- cout << "Create a Password: ";
- cin >> Password;
- ofstream file;
- file.open("data\\" + Username + ".txt");
- file << Username << endl;
- file << Password << endl;
- file.close();
- main();
- }
- else if(choice == 2){
- bool status = IsLoggedIn();
- if(!status){
- cout << "Wrong Username/Password" << endl;
- system("PAUSE");
- return 0;
- }
- else{
- cout << "Successfully logged in!" << endl;
- system("PAUSE");
- return 1;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement