hello freinds,
I am new to c++ and was fololwing a login system tutorial
everything worked fine till i tried to add encryption
before encryption
this actually works and reading data perfectly from users.dat and passwords.dat
Code:
#include<iostream>#include<fstream>
using namespace std;
class loginManager{
public:
loginManager(){
accessGranted =0;
}
void login()
{
cout<<"Hey you need to enter your username and password here\n Username:";
cin>>userNameAttempt;
userName = getFile("users.dat");
if(userNameAttempt==userName)
{
cout<<"Password: ";
cin>>passwordAttempt;
password = getFile("passwords.dat");
if(passwordAttempt==password)
{
cout<<"you are logged in"<<endl;
cin.get();
}
else
{
cout<<"wrong password"<<endl;
login();
}
}
else
{
cout<<"wrong username"<<endl;
login();
}
}
string getFile(const char* p_fileName)
{
string line;
fstream file;
file.open(p_fileName, ios::in);
if(file.is_open())
{
getline(file,line);
}
file.close();
return line;
}
private:
string password;
string userName;
string userNameAttempt;
string passwordAttempt;
bool accessGranted;
};
int main(){
loginManager loginManagerObj;
loginManagerObj.login();
cin.get();
return 0;
}
after encryption
Code:
#include<iostream>#include<fstream>
using namespace std;
class loginManager{
public:
loginManager(){
accessGranted =0;
}
void login()
{
cout<<"Hey you need to enter your username and password here\n Username:";
cin>>userNameAttempt;
userName = getFile("users.dat");
if(userNameAttempt==userName)
{
cout<<"Password: ";
cin>>passwordAttempt;
password = getFile("passwords.dat");
if(passwordAttempt==password)
{
cout<<"you are logged in"<<endl;
cin.get();
}
else
{
cout<<"wrong password"<<endl;
login();
}
}
else
{
cout<<"wrong username"<<endl;
login();
}
}
string getFile(const char* p_fileName)
{
string line;
fstream file;
file.open(p_fileName, ios::in);
if(file.is_open())
{
getline(file,line);
}
file.close();
return line;
}
void saveFile(string p_line,const *p_fileName)
{
fstream file;
file.open(p_fileName,ios::out);
for(int i=0;i<p_line.length();i++)
{
file<<encrypt(p_line[i]);
file<<"\n";
}
file<<"0";
file.close();
}
int encrypt(int p_letter)
{
return p_letter + 3;
}
int decrypt(int p_letter)
{
return p_letter - 3;
}
private:
string password;
string userName;
string userNameAttempt;
string passwordAttempt;
bool accessGranted;
};
int main(){
loginManager loginManagerObj;
loginManagerObj.saveFile("grapejuice","passwords.dat");
cin.get();
return 0;
}
i just ran this code to check if the encryption works or not but
it gives error on this line
Code:
file.open(p_fileName,ios::out);
saying no matching function for call
what am i missing here?