26 lines
547 B
Go
26 lines
547 B
Go
//
|
|
// helper.go
|
|
// Copyright (C) 2022 tiglog <me@tiglog.com>
|
|
//
|
|
// Distributed under terms of the MIT license.
|
|
//
|
|
|
|
package gauth
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
// 加密密码
|
|
func EncryptPassword(password string) (string, error) {
|
|
bt, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(bt), nil
|
|
}
|
|
|
|
// 检查密码
|
|
func CheckPassword(pwd_plain, pwd_hash string) bool {
|
|
err := bcrypt.CompareHashAndPassword([]byte(pwd_hash), []byte(pwd_plain))
|
|
return err == nil
|
|
}
|