Files
streamctl/pkg/mainprocess/password.go
2024-07-20 20:52:38 +01:00

28 lines
403 B
Go

package mainprocess
import (
"crypto/sha1"
"fmt"
)
func checkPassword(
a, b string,
) error {
// naive mostly-timing-attack-resistant comparison algo
h0 := sha1.Sum([]byte(a))
h1 := sha1.Sum([]byte(b))
match := true
for idx := range h0 {
charMatches := h0[idx] == h1[idx]
match = match && charMatches
}
if !match {
return fmt.Errorf("the password does not match")
}
return nil
}