Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <stdlib.h>
- #include <string>
- #include <stdio.h>
- using namespace std;
- const int AMNT=50;
- char filename[50];
- ifstream inputfile;
- int loginattempt =1;
- typedef char mychar;
- mychar FirstLine[AMNT];
- mychar SecondLine[AMNT];
- mychar ThirdLine[AMNT];
- struct UserRecord
- {
- string Username;
- string Password;
- char pin[20];
- }a;
- void wrong_input()
- {
- loginattempt =4;
- cout<<"Wrong input";
- system("pause");
- }
- void Open_Message()
- {
- cout<<"------------------------------"<<endl;
- cout<<"Welcome to MyGreatWebsite.com!"<<endl;
- cout<<"Please enter the following:"<<endl;
- cout<<"------------------------------"<<endl;
- }
- void Read_Input()
- {
- //struct UserRecord a;
- cout<<"Username:"<<endl;
- cin>>a.Username;
- cout<<"Password:"<<endl;
- cin>>a.Password;
- cout<<"PIN:"<<endl;
- //cin>>a.pin;
- int pin;
- if(cin>>pin){
- //sprintf(a.pin, 20, "%d", pin);
- cout<<"======================="<<endl;
- cout<<"Input is "<<endl;
- cout<<"Username: "<<a.Username<<endl;
- cout<<"Password: "<<a.Password<<endl;
- cout<<"PIN: "<<a.pin<<endl;
- cout<<"======================="<<endl;
- }
- else
- {
- wrong_input();
- }
- }
- int main(void)
- {
- //struct UserRecord a;
- Open_Message();
- Read_Input();
- //test open file for reading...
- inputfile.open("users.txt");
- //if not the end of file, do...
- if(!inputfile.eof())
- {
- //cout<<"\nThe first line of text is: \n";
- inputfile.getline(FirstLine, 50);
- // cout<<FirstLine<<'\n';
- // cout<<"The second line of text is: \n";
- inputfile.getline(SecondLine, 50);
- //cout<<SecondLine<<endl;
- //cout<<"The third line of text is: \n";
- inputfile.getline(ThirdLine, 50);
- //cout<<ThirdLine<<endl;
- string z= a.pin;
- if (FirstLine==a.Username && SecondLine == a.Password && ThirdLine==z){ // if login data is found
- cout << "Successful login! Welcome " << a.Username << endl;
- }
- else // if login data is not found
- {
- if(loginattempt<=3){
- cout << "\nUsername and/or password incorrect!\n\n\n\n";
- cout<<"Please try again"<<endl;
- loginattempt++;
- Read_Input();
- }
- else
- {
- cout << "\nUsername and/or password incorrect!\n\n\n\n";
- }
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement