feat: first version.

This commit is contained in:
tx7do
2023-05-18 13:06:55 +08:00
parent 75fcd82de5
commit ba93a75c5a
20 changed files with 1703 additions and 1 deletions

17
crypto/crypto.go Normal file
View File

@@ -0,0 +1,17 @@
package crypto
import (
"golang.org/x/crypto/bcrypt"
)
// HashPassword 加密密码
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 10)
return string(bytes), err
}
// CheckPasswordHash 校验密码
func CheckPasswordHash(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}