19 lines
553 B
Go
Executable File
19 lines
553 B
Go
Executable File
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
|
|
}
|