feat: hash the user password
This commit is contained in:
@ -32,6 +32,7 @@ import (
|
||||
"git.vinchent.xyz/vinchent/howmuch/internal/howmuch/usecase/repo"
|
||||
"git.vinchent.xyz/vinchent/howmuch/internal/pkg/errno"
|
||||
"git.vinchent.xyz/vinchent/howmuch/internal/pkg/log"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
var UserExisted = &errno.Errno{
|
||||
@ -57,6 +58,13 @@ func NewUserUsecase(r repo.UserRepository, d repo.DBRepository) User {
|
||||
}
|
||||
|
||||
func (uuc *userUsecase) Create(ctx context.Context, u *model.User) (*model.User, error) {
|
||||
// Hash the password
|
||||
encrypted, err := bcrypt.GenerateFromPassword([]byte(u.Password), 12)
|
||||
if err != nil {
|
||||
log.ErrorLog("encrypt password error", "err", err)
|
||||
return nil, errno.InternalServerErr
|
||||
}
|
||||
u.Password = string(encrypted)
|
||||
data, err := uuc.dbRepo.Transaction(
|
||||
ctx,
|
||||
func(txCtx context.Context, tx interface{}) (interface{}, error) {
|
||||
|
Reference in New Issue
Block a user