Created
March 17, 2020 16:14
-
-
Save siraajul/04a3b6b5fca3f91e706d9fc2910a7333 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Login and Registration Program | |
// Created by Parvez on 17/3/20. | |
// Copyright © 2020 Pacific Inc. All rights reserved. | |
#include<iostream> | |
#include<fstream> | |
using namespace std; | |
int main() | |
{ | |
string command,name, password,inName, inPassword,registerName, registerPassword; | |
while (1) | |
{ | |
cout<<"(register/exit/login)\n" | |
<<"Command: "; | |
getline(cin, command); | |
if (command=="exit") | |
{ | |
return 1; | |
} | |
if (command=="register") | |
{ | |
ofstream g("registration.txt"); | |
if (!g.is_open()) | |
{ | |
cout<<"could not open file\n"; | |
return 0; | |
} | |
cout<<"\n\n\n" | |
<<"New Username: "; | |
getline(cin, registerName); | |
cout<<"New Password: "; | |
getline(cin, registerPassword); | |
g<<registerName; | |
g<<'\n'; | |
g<<registerPassword; | |
g.close(); | |
} | |
if (command=="login") | |
{ | |
ifstream f("registration.txt"); | |
if (!f.is_open()) | |
{ | |
cout<<"could not open file\n"; | |
return 0; | |
} | |
getline(f, name, '\n'); | |
getline(f, password, '\n'); | |
f.close(); | |
while (1) | |
{ | |
cout<<"\n\n\n" | |
<<"Enter Username: "; | |
getline(cin, inName); | |
cout<<"Enter Password: "; | |
getline(cin, inPassword); | |
if (inName==name && inPassword==password) | |
{ | |
cout<<"Login Successful\n" | |
<<"Welcome, " | |
<<inName; | |
break; | |
} | |
cout<<"incorrect name or password\n"; | |
} | |
} | |
cout<<"\n\n\n\n\n"; | |
} | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment