Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Poojith-Patnala-s-Contribution/RegisterandLogin
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
74 lines (53 sloc)
1.59 KB
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
#include <iostream> | |
#include <fstream> | |
#include <string> | |
using namespace std; | |
bool LoggedIn() | |
{ | |
string username, password, name /*comparasion string */, code /*comparasion string */; | |
cout << "Enter Username: "; cin >> username; | |
cout << "Enter Password: "; cin >> password; | |
ifstream read("c:\\Users\\Rahul\\source\\repos\\RegisterAndLogin\\RegisterAndLogin\\LoginDetails\\" + username + ".txt"); //ifstream for reading a file// """ looking for the filename username """ | |
getline(read, name); // the read line for username | |
getline(read, code); // the read line for password | |
if (name == username && code == password) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
int main() | |
{ | |
int option; | |
cout << "1: Registration\n2 : Login\nYour option: "; cin >> option; | |
if (option == 1) { | |
string fullname, username, password; | |
cout << "Enter Full Name: "; | |
cin >> fullname; | |
cout << "Create a username: "; | |
cin >> username; | |
cout << "Enter a password: "; | |
cin >> password; | |
ofstream file; //ofstream for creating a file | |
file.open("c:\\Users\\Rahul\\source\\repos\\RegisterAndLogin\\RegisterAndLogin\\LoginDetails\\" + username + ".txt"); //open file | |
file <<fullname << endl << username << endl << password; | |
file.close(); //close file | |
main(); | |
} | |
else if (option == 2) { | |
bool status = LoggedIn; | |
if (!status) | |
{ | |
cout << "Unable to login, please check your username or password" << endl; | |
system("PAUSE"); | |
return 0; //return 0 as "int" main | |
} | |
else { | |
cout << " Logged in successfully!" << endl; | |
system("PAUSE"); | |
return 1; | |
} | |
} | |
} | |
}; |