mirror of
https://github.com/znc/znc.git
synced 2026-05-09 23:04:47 +02:00
Add sha256 support
This imports the sha256 code from http://www.ouah.org/ogay/sha2/ (The other hashes from sha-2 were removed). sha256 is a much stronger hashing algorithm than md5 is (There were successful birthday attacks against md5). All the code now defaults to creating sha256 salted hashes (The salting used is the same as before). Old znc.conf files can still be read. git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1618 726aef4b-f618-498e-8847-2d620e286838
This commit is contained in:
@@ -163,6 +163,9 @@ CString CUtils::GetHashPass() {
|
||||
}
|
||||
}
|
||||
|
||||
// If you change this here and in GetSaltedHashPass(),
|
||||
// don't forget CUser::HASH_DEFAULT!
|
||||
const CString CUtils::sDefaultHash = "sha256";
|
||||
CString CUtils::GetSaltedHashPass(CString& sSalt) {
|
||||
sSalt = GetSalt();
|
||||
|
||||
@@ -176,7 +179,7 @@ CString CUtils::GetSaltedHashPass(CString& sSalt) {
|
||||
CUtils::PrintError("You can not use an empty password");
|
||||
} else {
|
||||
// Construct the salted pass
|
||||
return SaltedHash(pass1, sSalt);
|
||||
return SaltedSHA256Hash(pass1, sSalt);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -185,10 +188,14 @@ CString CUtils::GetSalt() {
|
||||
return CString::RandomString(20);
|
||||
}
|
||||
|
||||
CString CUtils::SaltedHash(const CString& sPass, const CString& sSalt) {
|
||||
CString CUtils::SaltedMD5Hash(const CString& sPass, const CString& sSalt) {
|
||||
return CString(sPass + sSalt).MD5();
|
||||
}
|
||||
|
||||
CString CUtils::SaltedSHA256Hash(const CString& sPass, const CString& sSalt) {
|
||||
return CString(sPass + sSalt).SHA256();
|
||||
}
|
||||
|
||||
CString CUtils::GetPass(const CString& sPrompt) {
|
||||
PrintPrompt(sPrompt);
|
||||
return getpass("");
|
||||
|
||||
Reference in New Issue
Block a user