Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include "auth.hpp"
string Authentication::cipher_encryption(string password){
string cipher;
for(int i=0; i<password.length(); ++i){
int result = int(password[i]) + i + 3;
cipher.push_back(result);
}
return cipher;
}
string Authentication::cipher_decryption(string encrypted_password){
string orignal_password;
for(int i=0; i<encrypted_password.length(); ++i){
int result = int(encrypted_password[i]) - i - 3;
orignal_password.push_back(result);
}
return orignal_password;
}
void Authentication::new_user(string username , string password){
sqlite::sqlite db("gameDb.sqlite");
string encrypt_password = cipher_encryption(password);
auto cur = db.get_statement();
cur->set_sql("INSERT INTO 'user_login'"
"VALUES (?7, ?8)");
cur->prepare();
cur->bind(7,username);
cur->bind(8,encrypt_password);
cur->step();
cout<<"New Users Created Sucessfully"<<endl;
return;
}
bool Authentication::loginValidation(string username , string password){
sqlite::sqlite db("gameDb.sqlite");
auto cur1 = db.get_statement();
cur1->set_sql("SELECT * FROM 'user_login'");
cur1->prepare();
tuple<string,string>credentials;
while(cur1->step())
{
credentials = make_tuple(cur1->get_text(0),cur1->get_text(1));
}
string decrypt_password = cipher_decryption(get<1>(credentials));
if(username == get<0>(credentials) && password == decrypt_password)
{cout<<"Correct Credentials"<<endl;return true;}
else{cout<<"Wrong Credentials"<<endl;return false;}
}
void Authentication::change_password(string old_username ,string old_password, string new_password){
bool result = loginValidation(old_username , old_password);
if (result == true){
sqlite::sqlite db("gameDb.sqlite");
string encrypt_password = cipher_encryption(new_password);
auto cur = db.get_statement();
cur->set_sql("UPDATE 'user_login' SET password = (?4)"
" WHERE username = (?5);");
cur->prepare();
cur->bind(4,encrypt_password);
cur->bind(5,old_username);
cur->step();
cout<<"New password Created Sucessfully"<<endl;
}
else{cout<<"Wrong password please try again With correct password";}
return;
}
void Authentication::forget_password(string details){
return;
}
void Authentication::delete_user(string username , string password){
bool result = loginValidation(username , password);
if (result == true){
sqlite::sqlite db("gameDb.sqlite");
auto cur = db.get_statement();
cur->set_sql("DELETE FROM 'user_login' WHERE username = (?6)");
cur->prepare();
cur->bind(6,username);
cur->step();
}
}