2020-01-28 11:04:10 +01:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2020-02-21 01:14:45 +01:00
|
|
|
// CheckPassword compares given password p with the admin password
|
2020-01-28 11:04:10 +01:00
|
|
|
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
|
|
|
|
}
|