Remove legacy hashes
This commit is contained in:
@@ -79,24 +79,8 @@ std::string hashPassword(const std::string &password)
|
||||
|
||||
bool verifyPassword(const std::string &password, const std::string &hash)
|
||||
{
|
||||
constexpr std::string_view legacyPrefix = "sha256$";
|
||||
constexpr std::string_view pbkdf2Prefix = "pbkdf2_sha256$";
|
||||
|
||||
if (hash.starts_with(legacyPrefix))
|
||||
{
|
||||
const auto saltStart = legacyPrefix.size();
|
||||
const auto hashStart = hash.find('$', saltStart);
|
||||
if (hashStart == std::string::npos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto salt = hash.substr(saltStart, hashStart - saltStart);
|
||||
const auto expected =
|
||||
"sha256$" + salt + "$" + sha256(salt + ":" + password);
|
||||
return expected == hash;
|
||||
}
|
||||
|
||||
if (!hash.starts_with(pbkdf2Prefix))
|
||||
{
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user