feat: allow password change
All checks were successful
ci/woodpecker/tag/release Pipeline was successful

This commit is contained in:
Felipe M 2025-04-21 15:44:45 +02:00
parent ece8280358
commit 6aedfc794f
Signed by: fmartingr
GPG key ID: CCFBC5637D4000A8
4 changed files with 203 additions and 22 deletions

View file

@ -572,6 +572,25 @@ func (d *Database) CheckCredentials(username, password string) (*model.User, err
}, nil
}
// UpdateUserPassword updates a user's password
func (d *Database) UpdateUserPassword(userID int64, newPassword string) error {
// Hash the new password
hashedPassword, err := hashPassword(newPassword)
if err != nil {
return err
}
// Update the user's password
query := `
UPDATE users
SET password = ?
WHERE id = ?
`
_, err = d.db.Exec(query, hashedPassword, userID)
return err
}
// Helper function to hash password
func hashPassword(password string) (string, error) {
// Use bcrypt for secure password hashing