Set user password

This commit is contained in:
Eden Kirin
2023-10-26 17:40:05 +02:00
parent dd671d561c
commit 50187f5a34
5 changed files with 67 additions and 5 deletions

View File

@ -1,6 +1,8 @@
package models
import (
"iris-test/app/lib/auth"
"iris-test/app/lib/cfg"
"time"
)
@ -19,8 +21,12 @@ func (u *User) TableName() string {
return "users"
}
// func (u *User) SetPassword(password string) (string, error) {
// secretKey := common.Config.Application.SecretKey
// bytes, err := bcrypt.GenerateFromPassword([]byte(password+secretKey), 14)
// return string(bytes), err
// }
func (u *User) SetPassword(password string) error {
secretKey := cfg.Config.Application.SecretKey
hashedPassword, err := auth.HashPassword(password, secretKey)
if err != nil {
return err
}
u.Password = hashedPassword
return nil
}