Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <locale>
- #define VERSION "1.0"
- #define AUTHOR "Melvin Koopmans"
- using namespace std;
- string username;
- string password;
- string line;
- int option;
- char back;
- char loginyn;
- template < typename Iter >
- void range_tolower ( Iter beg, Iter end ) {
- for( Iter iter = beg; iter != end; ++iter ) {
- *iter = tolower( *iter );
- }
- }
- void string_tolower ( std::string & str ) {
- range_tolower( str.begin(), str.end() );
- }
- int loginform()
- {
- cout << "Login" << endl;
- cout << "Username: ";
- cin >> username;
- cout << "Password: ";
- cin >> password;
- string_tolower( username );
- ifstream datafile (username+".txt");
- if (datafile.is_open())
- {
- while (! datafile.eof() )
- {
- getline (datafile,line);
- if ( line == password )
- {
- cout << "Welcome " << username << "!" << endl;
- }
- }
- datafile.close();
- }
- else
- {
- cout << "Invalid login!" << endl;
- }
- return 0;
- }
- int registerform()
- {
- cout << "Register" << endl;
- backregister:
- cout << "Username: ";
- cin >> username;
- cout << "Password: ";
- cin >> password;
- string_tolower( username );
- ofstream datafile;
- datafile.open (username+".txt");
- datafile << password;
- datafile.close();
- cout << "Registed Succesfuly!" << endl;
- loginynback:
- cout << "Login now[y/n]?: ";
- cin >> loginyn;
- if ( loginyn == 'y' )
- {
- loginform();
- }
- else if ( loginyn == 'n')
- {
- }
- else
- {
- cout << "Invalid option!" << endl;
- goto loginynback;
- }
- return 0;
- }
- int main()
- {
- start:
- cout << "MyProgram " << VERSION << endl;
- cout << "1. Login" << endl;
- cout << "2. Register" << endl;
- cout << "3. Credits" << endl;
- cout << "4. Exit" << endl;
- cout << "Choose an option: ";
- cin >> option;
- if ( option == 1 )
- {
- loginform();
- }
- else if ( option == 2 )
- {
- registerform();
- }
- else if ( option == 3 )
- {
- cout << "Made by: Melvin Koopmans" << endl;
- cout << "Made in C++ " << endl;
- cout << " " << endl;
- back2:
- cout << "Back[y/n]?: ";
- cin >> back;
- if ( back == 'y' )
- {
- cout << " " << endl;
- goto start;
- }
- else if ( back == 'n' )
- {
- }
- else
- {
- cout << "Invalid option!" << endl;
- goto back2;
- }
- }
- else if ( option == 4 )
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement