mirror of
https://github.com/xaionaro-go/streamctl.git
synced 2025-09-27 03:45:52 +08:00
28 lines
403 B
Go
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
|
|
}
|