Buffer Overflow Two Fix to the Problem: Change #include to #include Change Password from a char array
Fantastic news! We've Found the answer you've been seeking!
Question:
Buffer Overflow Two Fix to the Problem: Change #include to #include Change Password from a char array to a C++ string: string Password; Change the comparison to be C++ string friendly: if (!Password.compare(“secret”)) Now run the program again typing any six characters and T as the seventh one.
code to change:
#include
#include
using namespace std;
int PasswordOkay() {
char Password[6];
char GoodPassword = 'F';
cin >> Password;
if (!strcmp(Password, "secret"))
GoodPassword = 'T';
return (GoodPassword == 'T');
}
int main() {
cout << "Enter Password:";
if (PasswordOkay())
cout << "Access Granted";
else
cout << "Access Denied";
return 0;
}
Related Book For
Financial Accounting
ISBN: 978-0078025549
3rd edition
Authors: J. David Spiceland, Wayne Thomas, Don Herrmann
Posted Date: