Encrypt encrypts the given plain-text password.
(plain string)
| 16 | |
| 17 | // Encrypt encrypts the given plain-text password. |
| 18 | func Encrypt(plain string) (string, error) { |
| 19 | if len(plain) < pwdLenLimit { |
| 20 | return "", errors.Errorf("Password too short, i.e. should have at least 6 chars") |
| 21 | } |
| 22 | |
| 23 | encrypted, err := bcrypt.GenerateFromPassword([]byte(plain), bcrypt.DefaultCost) |
| 24 | if err != nil { |
| 25 | return "", err |
| 26 | } |
| 27 | |
| 28 | return string(encrypted), nil |
| 29 | } |
| 30 | |
| 31 | // VerifyPassword checks that the plain-text password matches the encrypted password. |
| 32 | func VerifyPassword(plain, encrypted string) error { |