Initial DDC release
This commit is contained in:
commit
434f6441da
57 files changed
+4606
No files matched your search
Executable
+18
@@ -0,0 +1,18 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"crypto/subtle"
|
||||
)
|
||||
|
||||
func CredentialsMatch(expectedUsername, expectedPassword, username, password string) bool {
|
||||
usernameMatches := constantTimeEqual(expectedUsername, username)
|
||||
passwordMatches := constantTimeEqual(expectedPassword, password)
|
||||
return usernameMatches && passwordMatches
|
||||
}
|
||||
|
||||
func constantTimeEqual(expected, actual string) bool {
|
||||
expectedHash := sha256.Sum256([]byte(expected))
|
||||
actualHash := sha256.Sum256([]byte(actual))
|
||||
return subtle.ConstantTimeCompare(expectedHash[:], actualHash[:]) == 1
|
||||
}
|
||||
Reference in new issue
Block a user