Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stdlib.h>
- #include <fstream>
- #include<conio.h>
- #include<windows.h>
- #include<iomanip>
- using namespace std;
- bool login();
- void studlog();
- void reginput();
- int main(){
- studlog();
- cout<<"Program starts here";
- }
- void studlog(){
- bool on=true;
- int choice;
- while (on != false){
- cout << " S T U D E N T L O G I N\n";
- cout << "*******************************\n";
- cout << " 1 - Login.\n";
- cout << " 2 - Register.\n";
- cout << " 3 - Exit.\n";
- cout << "*******************************\n";
- cin>> choice;
- switch (choice)
- {
- case 1:
- system("cls");
- on = login();
- system("pause");
- system("cls");
- break;
- case 2:
- system("cls");
- reginput();
- system("pause");
- system("cls");
- break;
- case 3:
- on= false;
- break;
- }
- }
- }
- void reginput(){
- string regUser, regPass;
- cout<<"Username:";
- cin>>regUser;
- cout<<"Password:";
- cin>>regPass;
- ofstream file;
- file.open(regUser.c_str());
- file <<regUser<<endl<<regPass;
- file.close();
- }
- bool login(){
- string logUser;
- string logPass;
- string pass;
- string usern;
- cout<<"Enter Username: ";
- cin>> logUser;
- cout<<"Enter Password: ";
- cin>> logPass;
- ifstream read(logUser.c_str());
- getline(read, usern);
- getline(read, pass);
- if (usern == logUser && pass==logPass){
- cout << "You have been logged in!"<<endl;
- return false;
- }
- else{
- cout << "Invalid username or id!"<<endl;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement