feat: allow password change
All checks were successful
ci/woodpecker/tag/release Pipeline was successful
All checks were successful
ci/woodpecker/tag/release Pipeline was successful
This commit is contained in:
parent
ece8280358
commit
6aedfc794f
4 changed files with 203 additions and 22 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue