security: use constant-time comparison for auth credentials
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
999b115315
commit
e561e1ee1f
1 changed files with 4 additions and 3 deletions
|
|
@ -18,6 +18,7 @@ package lthn
|
|||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"crypto/subtle"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
|
|
@ -87,8 +88,8 @@ func createSalt(input string) string {
|
|||
|
||||
// Verify checks if an input string produces the given hash.
|
||||
// Returns true if Hash(input) equals the provided hash value.
|
||||
// Uses direct string comparison - for security-critical applications,
|
||||
// consider using constant-time comparison.
|
||||
// Uses constant-time comparison to prevent timing attacks.
|
||||
func Verify(input string, hash string) bool {
|
||||
return Hash(input) == hash
|
||||
computed := Hash(input)
|
||||
return subtle.ConstantTimeCompare([]byte(computed), []byte(hash)) == 1
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue