Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,9 @@ public static function maybe_show_last_login_failure_notice( $user ) {
if ( $last_failed_two_factor_login ) {
echo '<div id="login_notice" class="message"><strong>';
printf(
/* translators: 1: number of failed login attempts, 2: time since last failed attempt */
_n(
'WARNING: Your account has attempted to login 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.',
'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.',
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this requires updating the associated phpunit test case:

  1. Test_ClassTwoFactorCore::test_maybe_show_last_login_failure_notice
    Failed asserting that '
    WARNING: Your account has attempted to login 1 time without providing a valid two factor token. The last failed login occurred 5 seconds ago. If this wasn't you, you should reset your password.
    ' contains "login without providing a valid two factor token".

/var/www/html/wp-content/plugins/two-factor/tests/class-two-factor-core.php:630

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kasparsd thanks for the hint!

'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.',
$failed_login_count,
'two-factor'
Expand Down Expand Up @@ -917,6 +918,7 @@ public static function maybe_show_reset_password_notice( $errors ) {
$errors->add(
'two_factor_password_reset',
sprintf(
/* translators: %s: URL to create a new password. */
__( 'Your password was reset because of too many failed Two Factor attempts. You will need to <a href="%s">create a new password</a> to regain access. Please check your email for more information.', 'two-factor' ),
esc_url( add_query_arg( 'action', 'lostpassword', wp_login_url() ) )
)
Expand Down Expand Up @@ -1654,6 +1656,7 @@ public static function process_provider( $provider, $user, $is_post_request ) {
return new WP_Error(
'two_factor_too_fast',
sprintf(
/* translators: %s: human-readable time delay until another attempt can be made. */
__( 'ERROR: Too many invalid verification codes, you can try again in %s. This limit protects your account against automated attacks.', 'two-factor' ),
human_time_diff( $last_login + $time_delay )
)
Expand Down Expand Up @@ -1998,6 +2001,7 @@ private static function render_user_providers_form( $user, $providers ) {
<td>
<label class="two-factor-method-label">
<input id="enabled-<?php echo esc_attr( $provider_key ); ?>" type="checkbox" name="<?php echo esc_attr( self::ENABLED_PROVIDERS_USER_META_KEY ); ?>[]" value="<?php echo esc_attr( $provider_key ); ?>" <?php checked( in_array( $provider_key, $enabled_providers, true ) ); ?> />
<?php /* translators: %s: authentication method name. */ ?>
<strong><?php echo esc_html( sprintf( __( 'Enable %s', 'two-factor' ), $object->get_label() ) ); ?></strong>
<?php if ( in_array( $provider_key, $recommended_provider_keys, true ) ) : ?>
<abbr title="<?php esc_attr_e( 'This method is more secure and easy to use', 'two-factor' ); ?>" class="two-factor-method-recommended"><?php esc_html_e( 'Recommended', 'two-factor' ); ?></abbr>
Expand Down
3 changes: 2 additions & 1 deletion tests/class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,8 @@ public function test_maybe_show_last_login_failure_notice() {

$this->assertNotEmpty( $contents );
$this->assertStringNotContainsString( '1 times', $contents );
$this->assertStringContainsString( 'login without providing a valid two factor token', $contents );
$this->assertStringContainsString( 'attempted to login', $contents );
$this->assertStringContainsString( 'without providing a valid two factor token', $contents );

// 5 failed login attempts 5 hours ago - User should be informed.
$five_hours_ago = time() - 5 * HOUR_IN_SECONDS;
Expand Down