help with login system
Nov 18, 2014 at 6:02pm UTC
hi, i made a login system where i can change my info.
but when i change the info i can 't use the new ones when i run again.
i know that original strings are back to initial username and password.
i want to know how to put them in a .txt file and delete them then make new ones to get the info i edited in the second run of the program.
i suggest you to run the program so you can understand the code.
here is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
///login system
///gilbert Sassine
#include <cstdlib>
#include <iostream>
#include <windows.h>
using namespace std;
void seconds_count();
const int MAX_WRONG = 5;
string username = "gilbert" ;
string password = "toronto77889900" ;
int main()
{
system ("color 1f" );
MAINLOOP:
int wrong = 0;
string userChoice;
string userChoice2;
SYSTEM_LOOP:
system ("cls" );
cout << "Username : " << endl;
cin >> userChoice;
cout<<endl;
cout << "Password : " << endl;
cin >> userChoice2;
cout<<endl;
if (userChoice == username && userChoice2 == password)
{
cout<<"correct !" <<endl;
system ("pause" );
system ("cls" );
}
else if (userChoice != username && userChoice2 != password)
{
cout<<"incorrect !" <<endl;
wrong++;
system ("pause" );
if (wrong == MAX_WRONG)
{
seconds_count();
}
goto SYSTEM_LOOP;
}
else if (userChoice == username && userChoice2 != password)
{
cout<<"incorrect !" <<endl<<endl;
system ("pause" );
goto SYSTEM_LOOP;
}
else if (userChoice != username && userChoice2 == password)
{
cout<<"incorrect !" <<endl<<endl;
system ("pause" );
goto SYSTEM_LOOP;
}
cout<<"1) enter game" <<endl;
cout<<"2) edit username or password" <<endl;
cout<<"3) Exit " <<endl;
int choice;
cin>>choice;
switch (choice)
{
case 1:
cout<<"you are in the game" <<endl;
break ;
case 2:
enter_username:
system ("cls" );
cout<<"username : " <<username<<endl;
cout<<"password : " <<password<<endl;
cout<<"enter new username :" <<endl;
username = "" ;
cin>>username;
cout<<endl<<endl;
cout<<"enter new password" <<endl;
password = "" ;
cin>>password;
cout<<endl<<endl;
cout<<"re-enter your new password" <<endl;
string password_confirm = "" ;
cin>>password_confirm;
cout<<endl<<endl;
if (password_confirm != password)
{
cout<<"passwords didn 't match" <<endl;
username = "" ;
password = "" ;
system ("pause" );
goto enter_username;
}
else if (password_confirm == password)
{
cout<<"username and password changed successfully" <<endl;
cout<<"please login to continue..." <<endl<<endl;
system ("pause" );
goto MAINLOOP;
}
break ;
if (choice == 3)
{
goto END;
}
}
END:
return 0;
}
void seconds_count()
{
for (int c = 30 ; c > 0 ; c--)
{
cout<<"Please wait " <<c<<" seconds" <<endl;
Sleep (1000);
system ("cls" );
}
}
thank you !
return 0;
Last edited on Nov 18, 2014 at 6:03pm UTC
Topic archived. No new replies allowed.