Skip to content

Commit

Permalink
fix: invalidate email, phone OTPs on password change
Browse files Browse the repository at this point in the history
  • Loading branch information
hf committed Mar 19, 2024
1 parent 77cc7ac commit 90935ac
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion internal/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,20 @@ func (u *User) SetPassword(ctx context.Context, password string) error {

// UpdatePassword updates the user's password. Use SetPassword outside of a transaction first!
func (u *User) UpdatePassword(tx *storage.Connection, sessionID *uuid.UUID) error {
if err := tx.UpdateOnly(u, "encrypted_password"); err != nil {
// These need to be reset because password change may mean the user no longer trusts the actions performed by the previous password.
u.ConfirmationToken = ""
u.ConfirmationSentAt = nil
u.RecoveryToken = ""
u.RecoverySentAt = nil
u.EmailChangeTokenCurrent = ""
u.EmailChangeTokenNew = ""
u.EmailChangeSentAt = nil
u.PhoneChangeToken = ""
u.PhoneChangeSentAt = nil
u.ReauthenticationToken = ""
u.ReauthenticationSentAt = nil

if err := tx.UpdateOnly(u, "encrypted_password", "confirmation_token", "confirmation_sent_at", "recovery_token", "recovery_sent_at", "email_change_token_current", "email_change_token_new", "email_change_sent_at", "phone_change_token", "phone_change_sent_at", "reauthentication_token", "reauthentication_sent_at"); err != nil {
return err
}

Expand Down

0 comments on commit 90935ac

Please sign in to comment.