Skip to content

Commit 163bc04

Browse files
committed
Login and Registration: Populate username after password reset.
Accessibility: to meet WCAG 2.2/3.3.7: Redundant entry, the username should be auto-populated when a user performs a password reset. There is an existing cookie set that contains this information, but was deleted before displaying the login form. Move cookie deletion to occur after displaying login form and use to set `$user_login`. Props estelaris, alh0319, sabernhardt, oglekler, peterwilsoncc, rcreators, rishavdutta, chaion07, stoyangeorgiev, rinkalpagdar, pratiklondhe, lukasfritzedev, ferdoused, audrasjb, westonruter, joedolson. Fixes #60726. git-svn-id: https://develop.svn.wordpress.org/trunk@61610 602fd350-edb4-49c9-b593-d223f7449a82
1 parent db26faa commit 163bc04

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/wp-login.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,6 @@ function wp_login_viewport_meta() {
10001000

10011001
if ( ( ! $errors->has_errors() ) && isset( $_POST['pass1'] ) && ! empty( $_POST['pass1'] ) ) {
10021002
reset_password( $user, $_POST['pass1'] );
1003-
setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
10041003
login_header(
10051004
__( 'Password Reset' ),
10061005
wp_get_admin_notice(
@@ -1487,6 +1486,14 @@ function wp_login_viewport_meta() {
14871486
wp_clear_auth_cookie();
14881487
}
14891488

1489+
// Obtain user from password reset cookie flow before clearing the cookie.
1490+
$rp_cookie = 'wp-resetpass-' . COOKIEHASH;
1491+
if ( isset( $_COOKIE[ $rp_cookie ] ) && is_string( $_COOKIE[ $rp_cookie ] ) ) {
1492+
$user_login = sanitize_user( strtok( wp_unslash( $_COOKIE[ $rp_cookie ] ), ':' ) );
1493+
list( $rp_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) );
1494+
setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
1495+
}
1496+
14901497
login_header( __( 'Log In' ), '', $errors );
14911498

14921499
if ( isset( $_POST['log'] ) ) {

0 commit comments

Comments
 (0)