hey guys, this should be an easy one, i'm pretty noobish.
i'm trying to make a simple password-type thingy. all i need it to do is check a string input from the user, and execute code if the string matches what the program knows.
i'm sure you'll get what i'm trying to do with the code:
int main()
{
string psd;
cout << "enter password.\n";
getline( cin, psd );
if (psd == "joshua") cout << "it works!";
else cout << "you suck at life.";
_getch() //this is just to save me from it closing out while i debug
return 0;
}
i made another attempt at this same effort, convinced i could never get it right with what i was trying. so i did this:
if you couldn't tell, my computer keeps insulting me. can anybody tell me what i'm doing wrong?
i would appreciate it A LOT.
Hi,
strcmp (psd, "joshua") will return you "0" when both the strings are same, which is FALSE for an "if" i.e. if(0) so it will execute your "else" part. Thats why the result will be vice-versa in your case.
Few concerns, that you are not corcerned at this moment...
1. What if password typed by use is more than 7 characters?
2. Your binary (.EXE) may be opened by anyone to find strings, and "joshua" can be detected by attacker!
3. That string may also be changed!
Bookmarks