Hello,
I am working through Alex's excellent book, and while doing one of the practice exercises in the 'if statement' chapter which involved modifying a given password checker program
Code:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string password;
cout << "Enter your password: " << "\n";
getline( cin, password, '\n' );
if ( password == "xyzzy" )
{
cout << "Access allowed" << "\n";
}
else
{
cout << "Bad password. Denied access!" << "\n";
// returning is a convenient way to stop the program
return 0;
}
// continue onward!
}
When I built my modified code, my Kaspersky AV program quarantined it, claiming that it contained a trojan, is it possible that some content of the code has caused this, since the original did not throw this warning?
Code:
#include<iostream>
#include<string>
int main()
{
std::string uname;
std::string password;
std::cout << "Enter your username: " << "\n";
std::getline( std::cin, uname, '\n');
std::cout << "Enter your password: " << "\n";
std::getline( std::cin, password, '\n');
if(uname == "david" || password == "xyzzz")
{
std::cout << "Access granted Dave!" << "\n";
}
else if(uname == "claire" || password == "xyxyx")
{
std::cout << "Access granted Claire!" << "\n";
}
else
{
std::cout << "Access Denied!" << "\n";
return 0;
}
}
Thank you
Dave