1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
bool Password_Encryptor::AuthenticateLogin(string userpass, string Password, string Username){
ofstream out3 ("C:/Users/Default/AppData/Roaming/Pass Holder/temp3.dat");
out3 << "1 " << Username << endl;
out3.close();
ofstream out4 ("C:/Users/Default/AppData/Roaming/Pass Holder/temp4.dat");
out4 << "1 " << Password << endl;
out4.close();
//This function is to make sure the username and password entered by the user is correct
int size;
char *buf;
string hashText;
//Read in the SALT used for the previous userpass
ifstream in1(SALTfile, ios::in | ios::binary | ios::ate);
size = in1.tellg();
buf = new char[size + 1];
buf[size] = 0;
in1.seekg(0, ios::beg);
in1.read(buf, size);
in1.close();
string hexsalt = string(buf);
//Read in the IV used for the previous userpass
ifstream in2(IVfile, ios::in | ios::binary | ios::ate);
size = in2.tellg();
buf = new char[size + 1];
buf[size] = 0;
in2.seekg(0, ios::beg);
in2.read(buf, size);
in2.close();
string hexiv = string(buf);
//Read in the hash used for the previous userpass, this will be compared the to newly entered userpass encrypted with the previous SALT and IV
ifstream in3(UserpassFile, ios::in | ios::binary | ios::ate);
size = in3.tellg();
buf = new char[size + 1];
buf[size] = 0;
in3.seekg(0, ios::beg);
in3.read(buf, size);
in3.close();
string cipherText = string(buf);
//Recover the SALT and IV from the hex values in the file,
PKCS5_PBKDF2_HMAC<SHA256> pbkdf;
SecByteBlock recoveredkey(AES::DEFAULT_KEYLENGTH);
SecByteBlock recoveredsalt(AES::DEFAULT_KEYLENGTH);
StringSource saltDecoder(hexsalt,true,new HexDecoder(new ArraySink(recoveredsalt, recoveredsalt.size() ) ) );
test();
ofstream out1 ("C:/Users/Default/AppData/Roaming/Pass Holder/temp.dat");
out1 << "1 " << Password << endl;
out1 << "1 " << userpass << "\n2 " << Password << endl;
out1 << "1 " << recoveredkey << "\n2 " << recoveredkey.size() << "\n3 " << Password << "\n4 " << Password.size() << "\n5 " <<
recoveredsalt << "\n6 " << recoveredsalt.size() << "\n7 " << iterations ;
out1.close();
pbkdf.DeriveKey(recoveredkey, recoveredkey.size(), 0x00, (byte *) Password.data(), Password.size(), recoveredsalt, recoveredsalt.size(), iterations);
test();
SecByteBlock recoverediv(AES::BLOCKSIZE);
StringSource ivDecoder(hexiv,true,new HexDecoder(new ArraySink(recoverediv, recoverediv.size() ) ) );
//Encrypt the userpass that has been entered, using the SALT and IV stored in the file
SecByteBlock derivedkey(AES::DEFAULT_KEYLENGTH);
//Buffer that holds the derived key, purpose byte (unused), password bytes, salt bytes, iteration count (large as you can tolerate)
pbkdf.DeriveKey(derivedkey, derivedkey.size(), 0x00, (byte *) Password.data(), Password.size(), recoveredsalt, recoveredsalt.size(), iterations);
//Encrypt the userpass using key derived above, storing the hex encoded result into hashtext
CBC_Mode<AES>::Encryption aesencryption(derivedkey,derivedkey.size(),recoverediv);
StringSource encryptor(userpass, true, new StreamTransformationFilter(aesencryption, new HexEncoder( new StringSink(hashText))) );
//Return whether the comparison between the newly created hash, and the old hash is correct
return (hashText == cipherText);
}
|