Which have been broken already:
Also. NIST considers SHA-1 as obsolete since 2011. SHA-256 is somewhat safer for now.
We have some customer projects that uses a separate user table, in these cases we usually use a stronger hash implementation:
Method SetPassword(value As %String) As %Status
{
set i%password = ..HashPassword(value)
return $$$OK
}
ClassMethod HashPassword(
value As %String,
salt As %String = "") As %String
{
if salt = "" {
set salt = $$$lcase(##class(%xsd.hexBinary).LogicalToXSD($System.Encryption.GenCryptRand(32)))
}
set hash = $$$lcase(##class(%xsd.hexBinary).LogicalToXSD($System.Encryption.PBKDF2(value, 15000, salt,256,256)))
return $$$FormatText(hash_":"_salt)
}
Method IsPasswordMatch(plainTextPassword As %String) As %Boolean
{
set salt = $piece(..password, ":", 2)
return $$ConstantTimeCompare(..HashPassword(plainTextPassword, salt), ..password)
ConstantTimeCompare(a, b)
if $length(a) '= $length(b) return 0
for i=1:1:$length(a) {
// Convert char to ASCII code and then to bitstring.
set aChar = $factor($ascii($extract(a, i)))
set bChar = $factor($ascii($extract(b, i)))
set match = $bitlogic(aChar ^ bChar)
set all = $bitlogic(all | match)
}
// 00000000 = valid
return $bitfind(all, 1) = 0
}
- Log in to post comments


