Putting a password on the prog
Hey all, How would go about putting a 2-digit password or w/e into the code so the person who is running the program would have to know the password to gain access to the info the program holds? Also would I make case for when somebuddy types in the password or the wrong password. For example it would say "Correct password Welcome" or "wrong password please try again."
Try my optimize version. Fixed
Try to use my optimize version.
It is likely C version, but anyway more optimize about space and memory.
Regards. :)
Now I've fixed event when input data buffer longer than expected.
Thanks.
Regards. :D
Code:
#include <iostream>
using namespace std;
char def_pass[]="iloveyou";
int main()
{
static int i = strlen(def_pass)+1;
char* pPassword = new char[i];
cout << "Please enter the password:\n";
//cin >> pPassword; // ok, maybe error
fgets (&pPassword[0], i, stdin) ; // replacement
if (strcmp(pPassword,def_pass)!=0)
{
cerr << "Incorrect password.";
return 1;// exit program with error code = 1
}
cout << "Correct password.";
delete pPassword;
//
//program begin here!
//
return 0;
}