feat(auth): 添加用户登录功能
This commit is contained in:
1 parent
92a9e20934
commit
63c8f2980b
10 files changed
+210
-18
No files matched your search
@@ -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
|
||||
}
|
||||
Reference in new issue
Block a user