同步代码

This commit is contained in:
TsMask
2023-08-21 11:00:22 +08:00
parent 2735cc3009
commit 788f01674a
37 changed files with 2211 additions and 1 deletions

14
lib/password.go Normal file
View File

@@ -0,0 +1,14 @@
package lib
import "golang.org/x/crypto/bcrypt"
// Encrypt 加密明文密码
func Encrypt(password string) (string, error) {
hashedBytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(hashedBytes), err
}
// Compare 密文校验
func Compare(hashedPassword, password string) error {
return bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
}