fixed changing passwords in the backend

This commit is contained in:
z1glr
2025-01-30 18:49:26 +00:00
parent 34a7ae1dda
commit 9ce861040c

View File

@@ -23,8 +23,8 @@ type User struct {
} }
type UserChangePassword struct { type UserChangePassword struct {
UserName `json:"userName" validate:"required" db:"userName"` UserName UserName `json:"userName" validate:"required" db:"userName"`
Password string `json:"password" validate:"required,min=12"` Password string `json:"password" validate:"required,min=12"`
} }
// hashes a password // hashes a password
@@ -160,16 +160,16 @@ func (userName UserName) ChangePassword(password string) (string, error) {
return "", err return "", err
} else { } else {
execStruct := struct { execStruct := struct {
UserName `db:"userName"` UserName UserName `db:"userName"`
Password []byte `db:"password"` Password []byte `db:"password"`
TokenID string `db:"tokenID"` TokenID string `db:"tokenID"`
}{ }{
UserName: userName, UserName: userName,
Password: hash, Password: hash,
TokenID: uuid.NewString(), TokenID: uuid.NewString(),
} }
if _, err := db.DB.NamedExec("UPDATE USERS SET tokenID = :tokenID, password = :password WHERE name = :userName", execStruct); err != nil { if _, err := db.DB.NamedExec("UPDATE USERS SET tokenID = :tokenID, password = :password WHERE userName = :userName", execStruct); err != nil {
return "", err return "", err
} else { } else {
return execStruct.TokenID, nil return execStruct.TokenID, nil