Password change

This commit is contained in:
Matthew Dillon 2015-10-12 20:43:59 -07:00
parent 0331834b92
commit e283ec7004
3 changed files with 34 additions and 0 deletions

View file

@ -166,3 +166,26 @@ func ListUsers(opt helpers.ListOptions, claims *types.Claims) (*Users, error) {
return &users, nil
}
func UpdateUserPassword(id int64, password string) error {
user, err := DbGetUserByID(id)
if err != nil {
return err
}
hash, err := bcrypt.GenerateFromPassword([]byte(password), 12)
if err != nil {
return err
}
user.Password = string(hash)
count, err := DBH.Update(user.UserBase)
if err != nil {
return err
}
if count != 1 {
return errors.ErrUserNotUpdated
}
return nil
}