Skip to content

Backup codes are saved before user intends #507

Open

Description

@iandunn

Currently, clicking the Generate verification codes button will generate codes and save them to usermeta. I think most users will only expect the codes to be saved if they click the Update Profile button.

If they navigate away from the page without clicking that, they'll assume nothing has changed, but in reality it has. This can be a problem if they already had existing codes, and accidentally clicked the button, or clicked it intentionally but then decided they didn't want new codes. Their old codes are now invalid, but they don't know that and won't save the new ones. They could be locked out in the future because their saved codes no longer work.

Activity

  1. jeffpaul commented on Jan 25, 2023

    @jeffpaul
    Member

    Alternatively, I might suggest we change the button to Generate verification codes and save to profile (or some better worded text) as (1) that seems like a better state to get users to, (2) I don't expect (m)any people want to just generate codes and not make them what relates to their user account, (3) its possible folks would click a Generate verification codes button and not realize they need to click Update Profile to save those codes to their profile.

  2. iandunn commented on Jan 26, 2023

    @iandunn
    MemberAuthor

    change the button to Generate verification codes and save to profile (or some better worded text)

    That (or some text near the button) could be a good alternative 👍🏻 The most important thing is that the user is informed about what will happen.

    I don't expect (m)any people want to just generate codes and not make them what relates to their user account

    I was thinking of situations where the user accidentally clicks the button, or when they click it and then want to "undo" that by leaving the page without saving. That could be the case if someone is running low on codes and decides to regenerate, but then discovers their printer isn't working or something, so they want to come back and do it later.

    Those are admittedly edge cases, though.

    not realize they need to click Update Profile to save those codes

    That's a fair point, especially since the current precedent is that you don't need to. Not having to click Update is inconsistent with the rest of the setting on that page, though, and some of the Two Factor settings. IMO it'd best for UX if everything is consistent.

    This isn't something I feel strongly about, though, it's an edge case and I can see your point of view 👍🏻

  3. pkevan commented on Jan 27, 2023

    @pkevan
    Contributor

    Perhaps some kind of confirmation dialogue would help with the accidental (or intentional) click, and draw their attention to the fact that codes will be updated?

  4. dd32 commented on Feb 10, 2023

    @dd32
    Member

    This could be dealt with the same as the TOTP setup process.

    Rather than generating and saving them server-side before showing the UI, they could be generated, provided to the client, and only hashed/saved server-side upon a second API request after user action. If we need to validate that the server generated the codes (to prevent someone sending bad-random codes?) a signature could be included if required..

    That wouldn't prevent the UI being changed to "Generate and save" though.

  5. timiwahalahti commented on Feb 22, 2023

    @timiwahalahti

    A better procedure is needed indeed. Locked my .org account yesterday, as I didn't expect visiting the backup codes page also to trigger those to be activated. Especially since I didn't manage to set up any TOTP a few moments earlier (because of now fixed bug).

    Is there a reason why backup codes should even be generated if 2FA is not activated?

  6. added this to the 0.9.0 milestone on Mar 2, 2023
  7. modified the milestones: 0.9.0, 0.10.0 on May 8, 2024
  8. modified the milestones: 0.14.0, 0.15.0 on Jul 3, 2025
  9. modified the milestones: 0.14.2, 0.15.0 on Dec 11, 2025
  10. modified the milestones: 0.15.0, 0.16.0 on Feb 18, 2026
  11. masteradhoc commented on Feb 22, 2026

    @masteradhoc
    Collaborator

    Hey @dd32 @iandunn
    I noticed this issue has already been resolved in the wp.org version of Two‑Factor. Would you be open to bringing that fix back into this plugin as well?

    I tested the wp.org version and it works great. It would be awesome to streamline things so the behavior is consistent here too. 🙂

  12. dd32 commented on Feb 22, 2026

    @dd32
    Member

    @masteradhoc The WordPress.org version has the same issue at present, AFAIK, it's just the custom UI is attempting to force the user to save them and stores a value that the user confirmed they saved them.

    Unfortunately many users still do not save the recovery tokens.

    Note: The wp.org custom UI and two-factor customizations is here: https://github.com/wordpress/wporg-two-factor All of the code can be pulled back to two-factor without concern if so desired.

  13. modified the milestones: 0.16.0, 0.17.0 on Mar 2, 2026
  14. modified the milestones: 0.17.0, 0.18.0 on Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions