Skip to content

Users: Record and display UTC timestamp when a user's password is set or changed - #16344

Open
rubenwoudsma wants to merge 2 commits into
WordPress:trunkfrom
rubenwoudsma:trac-66881-password-last-changed
Open

rubenwoudsma wants to merge 2 commits into
WordPress:trunkfrom
rubenwoudsma:trac-66881-password-last-changed

Conversation

@rubenwoudsma

@rubenwoudsma rubenwoudsma commented Nov 30, 2026 •

Copy link
Copy Markdown

Summary

Implements Trac #66881 by recording a policy-neutral UTC Unix timestamp (password_last_changed user meta) whenever a user's primary password is confirmed saved via Core APIs, displaying a localized read-only Last changed date under Account Management on profile.php / user-edit.php, and exporting the timestamp in the native WordPress User Personal Data Exporter.

Key Details

  1. Post-persistence timestamp recording (src/wp-includes/user.php, src/wp-includes/pluggable.php):
    • Adds wp_update_password_last_changed( $user_id ) (guarded by the wp_should_update_password_last_changed filter) and invokes it only after confirmed $wpdb->users persistence in wp_insert_user() (initial password creation and wp_update_user() / direct wp_insert_user() password updates) and wp_set_password() (explicit sets and reset_password()).
    • Ensures rejected updates (for example, wp_update_user() validation errors or aborted wp_pre_insert_user_data saves where do_action( 'wp_set_password' ) has already fired) leave password_last_changed unchanged while keeping existing wp_set_password hook behavior intact.
    • Ignores empty passwords (such as accounts created without an initial password) and leaves pre-existing accounts without a recorded meta value untouched rather than fabricating a fallback date.
  2. Preserves timestamp across transparent login rehashing (src/wp-includes/user.php):
    • Temporarily suppresses wp_update_password_last_changed() via wp_should_update_password_last_changed (inside a try / finally block) when wp_authenticate_username_password() or wp_authenticate_email_password() transparently upgrades an existing password hash via wp_password_needs_rehash(), ensuring algorithm/cost upgrades at sign-in never falsify when the user actually changed their password.
  3. Profile & Edit User screen (src/wp-admin/user-edit.php):
    • Displays Last changed: <localized date> (wp_date( __( 'F j, Y' ), $password_last_changed )) beneath Set New Password when password_last_changed > 0, hidden when no timestamp has been recorded.
  4. Personal Data Exporter (src/wp-includes/user.php):
    • Exports User Password Last Changed (Y-m-d H:i:s UTC, matching User Registration Date) in wp_user_personal_data_exporter() when recorded, and omits it when absent.
  5. Unit tests (tests/phpunit/tests/user/wpUpdatePasswordLastChanged.php, tests/phpunit/tests/user.php):
    • Covers wp_insert_user() creation and direct updates, empty-password/invalid-ID handling, wp_update_user() (profile-only edits, successful password changes, and rejected updates preserving both user_pass and password_last_changed), wp_set_password(), reset_password(), transparent legacy $P$ hash upgrades during username and email authentication, and wp_user_personal_data_exporter().

Trac ticket: https://core.trac.wordpress.org/ticket/66881

Testing Instructions

  1. Run the PHPUnit tests:
    composer test:php -- --group 66881
    composer test:php -- --group user
  2. Open Users → Profile (wp-admin/profile.php) for an existing account prior to changing its password and confirm no fabricated Last changed: line is shown.
  3. Set a new password under Account Management → New Password, save the profile, and confirm Last changed: <today's localized date> appears beneath Set New Password.
  4. Generate a Personal Data Export under Tools → Export Personal Data for that user and confirm User Password Last Changed is included in the User group.

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity, ChatGPT
Model(s): Gemini, GPT
Used for: Code-path analysis (including wp_password_needs_rehash() login interaction and post-persistence ordering in wp_update_user()), drafting the implementation and PHPUnit test cases, 4-eyes review, and verifying Coding Standards / PHPStan / PHPUnit checks. Reviewed and directed by me (@rubenwoudsma / rubenw).


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@rubenwoudsma
rubenwoudsma marked this pull request as ready for review November 30, 2026 14:18
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props rubenw.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant