Hey,
I've just started programming in C++, and after reading (quite a lot) today, I managed to put together an extremely crude login for a terminal based application. My code is as follows:
Code:
#include <iostream>
//An attempt at password protection
//By J_K9 -- 10/07/2005
int main()
{
const int passwd = 13579;
int input_passwd;
std::cout << "Please enter your password: ";
std::cin >> input_passwd;
if (input_passwd == passwd)
std::cout << "\nEnter!\n";
else
std::cout << "\nSorry! Wrong password!\n";
return 0;
}
I have compiled this and I know it works, but I had an odd complaint from g++ when I tried replacing the "int" values with "char", and changing the passwd to "lycrolite" (including speech marks). The error I received was:
Code:
jk9@ubuntu:~/CPP/000my_stuff/pass_prot2$ g++ passprot2.cpp
passprot2.cpp: In function `int main()':
passprot2.cpp:8: error: invalid conversion from `const char*' to `char'
I don't really understand this error...invalid conversion? I declared my constant and my variable, only initialized my constant, but the compiler is telling me that there is an invalid conversion?
Anyway, I know that this is a very crude way of password protection, and I'm guessing it's insecure(?), but I was wondering what other ways there are of password protecting something in C++ code. Thanks in advance,
J_K9
P.S Is it possible to decompile an a.out file to view the original C++ source?