Utils/Crypto: Use better method for GenerateSecret

Thanks to micolous for the suggestion
This commit is contained in:
tt2468 2021-09-24 18:39:46 -07:00
parent 61973e75dc
commit c73a153c9a

View File

@ -25,19 +25,15 @@ std::string Utils::Crypto::GenerateSalt()
std::string Utils::Crypto::GenerateSecret(std::string password, std::string salt) std::string Utils::Crypto::GenerateSecret(std::string password, std::string salt)
{ {
// Concatenate the password and the salt // Create challenge hash
QString passAndSalt = ""; auto challengeHash = QCryptographicHash(QCryptographicHash::Algorithm::Sha256);
passAndSalt += QString::fromStdString(password); // Add password bytes to hash
passAndSalt += QString::fromStdString(salt); challengeHash.addData(QByteArray::fromStdString(password));
// Add salt bytes to hash
challengeHash.addData(QByteArray::fromStdString(salt));
// Generate a SHA256 hash of the password and salt // Generate SHA256 hash then encode to Base64
auto challengeHash = QCryptographicHash::hash( return challengeHash.result().toBase64().toStdString();
passAndSalt.toUtf8(),
QCryptographicHash::Algorithm::Sha256
);
// Encode SHA256 hash to Base64
return challengeHash.toBase64().toStdString();
} }
bool Utils::Crypto::CheckAuthenticationString(std::string secret, std::string challenge, std::string authenticationString) bool Utils::Crypto::CheckAuthenticationString(std::string secret, std::string challenge, std::string authenticationString)