feat(auth): 添加用户登录功能

This commit is contained in:
unclesam committed 2026-07-07 22:19:37 +08:00
1 parent 92a9e20934
commit 63c8f2980b
10 files changed
+210 -18

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
package pwd
import (
"go.uber.org/zap"
"golang.org/x/crypto/bcrypt"
)
func GenerateFromPassword(password string) (string, error) {
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
if err != nil {
zap.L().Error("密码加密失败", zap.Error(err))
return "", err
}
return string(hashedPassword), nil
}
func CompareHashAndPassword(hashedPassword string, password string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
return err == nil
}