Skip to content

Commit 975c808

Browse files
dknaussclaude
andcommitted
fix: reword mixed-audience login failure notice to be informational
The previous notice used "WARNING:" and "If this wasn't you, you should reset your password." The reader has already entered the correct password, so the "if this wasn't you" framing is disorienting for the legitimate user (who likely mistyped a code) and the "reset your password" advice is wrong — the threat is to the second factor, not the password. New text is factual and defers action to after a successful login. Fixes #919 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent de069f3 commit 975c808

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

class-two-factor-core.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,10 +1004,10 @@ public static function maybe_show_last_login_failure_notice( $user ) {
10041004
echo '<div id="login_notice" class="message"><strong>';
10051005
printf(
10061006
esc_html(
1007-
/* translators: 1: number of failed login attempts, 2: time since last failed attempt */
1007+
/* translators: 1: number of failed verification code attempts, 2: human-readable time since the last attempt, e.g. "5 minutes" */
10081008
_n(
1009-
'WARNING: Your account has attempted to login %1$s time without providing a valid two factor token. The last failed login occurred %2$s ago. If this wasn\'t you, you should reset your password.',
1010-
'WARNING: Your account has attempted to login %1$s times without providing a valid two factor token. The last failed login occurred %2$s ago. If this wasn\'t you, you should reset your password.',
1009+
'%1$s failed verification code attempt on this account. The last attempt was %2$s ago. If you did not make this attempt, review your account security after logging in.',
1010+
'%1$s failed verification code attempts on this account. The last attempt was %2$s ago. If you did not make these attempts, review your account security after logging in.',
10111011
$failed_login_count,
10121012
'two-factor'
10131013
)

tests/class-two-factor-core.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -773,8 +773,7 @@ public function test_maybe_show_last_login_failure_notice() {
773773

774774
$this->assertNotEmpty( $contents );
775775
$this->assertStringNotContainsString( '1 times', $contents );
776-
$this->assertStringContainsString( 'attempted to login', $contents );
777-
$this->assertStringContainsString( 'without providing a valid two factor token', $contents );
776+
$this->assertStringContainsString( 'failed verification code attempt', $contents );
778777

779778
// 5 failed login attempts 5 hours ago - User should be informed.
780779
$five_hours_ago = time() - 5 * HOUR_IN_SECONDS;
@@ -785,10 +784,31 @@ public function test_maybe_show_last_login_failure_notice() {
785784
$contents = ob_get_clean();
786785

787786
$this->assertNotEmpty( $contents );
788-
$this->assertStringContainsString( '5 times', $contents );
787+
$this->assertStringContainsString( 'failed verification code attempts', $contents );
789788
$this->assertStringContainsString( human_time_diff( $five_hours_ago ), $contents );
790789
}
791790

791+
/**
792+
* Test that the login failure notice uses calm, informational language.
793+
*
794+
* @covers Two_Factor_Core::maybe_show_last_login_failure_notice()
795+
*/
796+
public function test_login_failure_notice_language_is_calm_and_informational() {
797+
$user = $this->get_dummy_user();
798+
update_user_meta( $user->ID, Two_Factor_Core::USER_FAILED_LOGIN_ATTEMPTS_KEY, 3 );
799+
update_user_meta( $user->ID, Two_Factor_Core::USER_RATE_LIMIT_KEY, time() - 60 );
800+
801+
ob_start();
802+
Two_Factor_Core::maybe_show_last_login_failure_notice( $user );
803+
$contents = ob_get_clean();
804+
805+
$this->assertStringNotContainsString( 'WARNING', $contents );
806+
$this->assertStringNotContainsString( "wasn't you", $contents );
807+
$this->assertStringNotContainsString( 'reset your password', $contents );
808+
$this->assertStringContainsString( 'failed verification code', $contents );
809+
$this->assertStringContainsString( 'review your account security', $contents );
810+
}
811+
792812
/**
793813
* Test no reset notice when no errors.
794814
*

0 commit comments

Comments
 (0)