18 lines
375 B
Go
18 lines
375 B
Go
package auth
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
const bcryptCost = 12
|
|
|
|
func HashPassword(plain string) (string, error) {
|
|
b, err := bcrypt.GenerateFromPassword([]byte(plain), bcryptCost)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(b), nil
|
|
}
|
|
|
|
func CheckPassword(hash, plain string) bool {
|
|
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(plain)) == nil
|
|
}
|