7ecc146460
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
26 lines
399 B
Go
26 lines
399 B
Go
package config
|
|
|
|
import (
|
|
"regexp"
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
func isBcrypt(s string) bool {
|
|
b, err := regexp.MatchString(`^\$2[ayb]\$.{56}$`, s)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
return b
|
|
}
|
|
|
|
func (c *Config) CheckPassword(p string) bool {
|
|
ap := c.AdminPassword()
|
|
|
|
if isBcrypt(ap) {
|
|
err := bcrypt.CompareHashAndPassword([]byte(ap), []byte(p))
|
|
return err == nil
|
|
}
|
|
|
|
return ap == p
|
|
}
|