diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 33097fb..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,69 +0,0 @@ -# Changelog - -All notable changes to this project are documented in this file. -Format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - -## [Unreleased] - -## [0.3.0] - 2026-06-05 - -### Added - -- Delete-on-uninstall option in admin settings Data Management section (off by default — all data is preserved). - -### Changed - -- Network admin settings page now correctly saves to `wp_sitemeta` via a dedicated `network_admin_edit_` handler. -- Settings option stored with `autoload=false` — not needed on every page load. -- Recovery code preview transient TTL reduced from 0 (persistent) to 300 seconds (5 minutes). - -### Security - -- Email verification codes now use `random_int()` (CSPRNG) instead of `wp_rand()` (Mersenne Twister), consistent with recovery codes and OTP secrets. - -### Fixed - -- `get_required_capability()` now returns `manage_network_options` in network admin context. -- `bin/deploy.sh` now excludes `CLAUDE.md`, `AGENTS.md`, `README.md`, `DOCUMENTATION-*.md`, and `.phpunit.result.cache` from the ZIP artifact. -- `update.json` corrected: was shipping SMTP plugin data instead of 2FA plugin data. - -## [0.2.0] - 2026-06-05 - -### Added - -- Per-role 2FA method matrix: admins choose exactly which verification methods (email, OTP, recovery codes) are required for each WordPress role, with select-all row and column toggles. -- Authenticator app (TOTP) support: secrets stored as Base32, QR code rendered via `bacon/bacon-qr-code`, manual setup key displayed as fallback. -- Recovery codes: 10 single-use 8-digit codes, one-time display grid with copy-to-clipboard, mandatory confirmation before activation, auto-refresh when batch exhausted. -- Email verification codes: 7-digit codes, 10-minute expiry, 60-second resend throttle. -- Configurable verification frequency remembered per device fingerprint (every login / daily / weekly / monthly); administrators can lock the global schedule. -- Dedicated stage token (WP nonce) securing the 2FA screen between password validation and code entry. -- Method-switch links on the verification screen (OTP ↔ email ↔ recovery codes) without restarting the login. -- Multisite support: `Network: true` header; network admins set and lock enforcement settings. -- `uninstall.php` removes all plugin options and user meta on deletion. -- `bin/deploy.sh` for manual ZIP packaging. -- PHPUnit test suite with plugin-header tests. - -### Changed - -- Settings UI replaces flat forced-roles list with per-role method matrix; existing `force_roles` + `default_method` data is automatically migrated. -- Profile method checkboxes require explicit confirmation before activating (OTP: valid 6-digit code; recovery codes: enter one displayed code). -- Required methods indicated with a "required for your role" badge in the profile; checkboxes disabled and hidden inputs ensure values survive submission. -- Login screen hides username/password fields, removes Remember Me, focuses code input, and auto-submits when digit count is reached. - -### Fixed - -- QR generation errors caught and surfaced to administrators; graceful fallback to text setup key. -- Recovery-code preview persists via transient until explicitly acknowledged. - -### Security - -- All `$_POST`/`$_GET`/`$_SERVER` reads guarded with `is_string()` before passing to sanitize functions. -- PHPStan level 9 passes with zero errors; no mixed-type casts. -- `composer audit`: no known vulnerabilities in any dependency. - -## [0.1.0] - 2024-04-08 - -### Added - -- Initial plugin skeleton with placeholder classes for login handling, user profile, and admin settings. -- Initial documentation files. diff --git a/assets/css/profile.css b/assets/css/profile.css index e1f3875..bbc0655 100644 --- a/assets/css/profile.css +++ b/assets/css/profile.css @@ -1,44 +1,64 @@ -.robotstxt-2fa-method-list { - margin-top: 0.5em; -} - -.robotstxt-2fa-method { - margin-bottom: 1.5em; -} - -.robotstxt-2fa-method:last-of-type { - margin-bottom: 0; -} - -.robotstxt-2fa-otp-qr { - height: auto; - max-width: 220px; -} - -.robotstxt-2fa-recovery-code-grid { - display: grid; - gap: 8px 16px; - grid-template-columns: repeat(2, minmax(140px, 1fr)); -} - -.robotstxt-2fa-recovery-code-row { - display: contents; -} - -.robotstxt-2fa-recovery-code-item { - font-size: 1.2em; - font-weight: 600; -} - -.robotstxt-2fa-recovery-confirm { - margin-top: 1em; -} - -.robotstxt-2fa-recovery-confirm label { - display: block; - margin-bottom: 0.5em; -} - -.robotstxt-2fa-recovery-confirm input { - max-width: 200px; -} +.robotstxt-2fa-method-list { + margin-top: 0.5em; +} + +.robotstxt-2fa-method { + margin-bottom: 1.5em; +} + +.robotstxt-2fa-method:last-of-type { + margin-bottom: 0; +} + +.robotstxt-2fa-otp-qr { + display: block; + height: auto; + margin: 0.75em 0; + max-width: 200px; +} + +/* Recovery codes preview block */ +.robotstxt-2fa-recovery-preview { + margin: 0.75em 0 0.5em; +} + +.robotstxt-2fa-recovery-code-list { + display: grid; + font-family: monospace; + font-size: 1em; + gap: 4px 2em; + grid-template-columns: repeat(2, max-content); + list-style: none; + margin: 0.5em 0 1em; + padding: 0; +} + +.robotstxt-2fa-recovery-code-list li code { + background: #f6f7f7; + border: 1px solid #dcdcde; + border-radius: 2px; + display: inline-block; + font-size: 1em; + letter-spacing: 0.05em; + padding: 3px 8px; +} + +.robotstxt-2fa-recovery-copy-feedback { + color: #1d7548; + margin-left: 0.75em; +} + +/* Confirmation input */ +.robotstxt-2fa-recovery-confirm { + margin-top: 0.75em; +} + +.robotstxt-2fa-recovery-confirm label { + display: block; + font-weight: 600; + margin-bottom: 0.4em; +} + +.robotstxt-2fa-recovery-confirm input { + max-width: 180px; +} diff --git a/changelog.txt b/changelog.txt index 3474b0d..e7adc9c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,35 @@ ## [Unreleased] +## [1.0.0] - 2026-06-05 + +### Fixed + +- Enable 2FA checkbox now defaults to email and pre-checks it in the UI on first activation. +- QR code for authenticator apps now displays correctly in the user profile. +- "Send the code again" link is disabled for 60 seconds after delivery with a live countdown. + +### Changed + +- Recovery codes section redesigned: plain list with code chips, no coloured notification box. +- 2FA login screen links now in a vertical list for better readability. + +### Removed + +- "Generate new secret" button from the OTP section. + +**Compatibility** + +* WordPress: 6.4 – 7.1 +* PHP: 8.2 – 8.5 + +**Tests** + +* PHP Coding Standards: PHP_CodeSniffer 3.13.5 / WPCS 3.3.0 +* PHPStan: level 9 — 0 errors +* PHPCompatibility: 8.2–8.5 — 0 issues +* PHPUnit: 9.6.34 — 42 tests, 109 assertions + ## [0.3.0] - 2026-06-05 ### Added diff --git a/includes/login/class-email-code-sender.php b/includes/login/class-email-code-sender.php index 41378c7..957fd61 100644 --- a/includes/login/class-email-code-sender.php +++ b/includes/login/class-email-code-sender.php @@ -52,7 +52,16 @@ class Email_Code_Sender { * @return int */ public function get_code_length(): int { - return self::CODE_LENGTH; + return self::CODE_LENGTH; + } + + /** + * Retrieve the minimum seconds that must elapse between resends. + * + * @return int + */ + public function get_resend_interval(): int { + return self::RESEND_INTERVAL; } /** diff --git a/includes/login/class-login-form-manager.php b/includes/login/class-login-form-manager.php index 5690b5a..4514587 100644 --- a/includes/login/class-login-form-manager.php +++ b/includes/login/class-login-form-manager.php @@ -287,44 +287,23 @@ class Login_Form_Manager { ); } - if ( ! empty( $alternates ) ) { - $link_markup = array(); - - foreach ( $alternates as $alternate ) { - $link_markup[] = sprintf( - '%2$s', - esc_url( $alternate['url'] ), - esc_html( $alternate['label'] ) - ); - } - - printf( - '

%1$s %2$s

', - esc_html__( 'Prefer a different verification method?', 'robotstxt-2fa' ), - wp_kses_post( implode( ' ', $link_markup ) ) - ); - } - $back_url = wp_login_url( $this->get_requested_redirect() ); ?> - get_requested_login(); + $login = $this->get_requested_login(); + $method = $this->get_requested_method(); + $sent_at = 0; + + if ( 'email' === $method && '' !== $login ) { + $user = get_user_by( 'login', $login ); + + if ( $user instanceof \WP_User ) { + $challenge = $this->user_settings_repository->get_email_challenge( $user->ID ); + $sent_at = $challenge['sent_at']; + } + } ?>

- <?php esc_attr_e( 'Authenticator app QR code', 'robotstxt-2fa' ); ?> + <?php esc_attr_e( 'Authenticator app QR code', 'robotstxt-2fa' ); ?>

@@ -374,13 +369,7 @@ class Profile_Settings { -

- -

- @@ -426,42 +415,33 @@ class Profile_Settings {

-
+

-
- -
- -
- - - -
 
- -
+
    + +
  • -
- -

+ +

-
-

- -

@@ -540,7 +520,16 @@ class Profile_Settings { } } - toggle.addEventListener( 'change', applyState ); + toggle.addEventListener( 'change', function () { + applyState(); + // Pre-check email when enabling 2FA for the first time. + if ( toggle.checked ) { + var emailCheckbox = document.getElementById( 'robotstxt-2fa-method-email' ); + if ( emailCheckbox && ! emailCheckbox.checked ) { + emailCheckbox.checked = true; + } + } + } ); applyState(); }()); @@ -717,12 +706,6 @@ class Profile_Settings { $otp_was_enabled = in_array( 'otp', $previous_methods, true ); $recovery_was_enabled = in_array( 'recovery_codes', $previous_methods, true ); - $otp_regenerate_requested = isset( $_POST[ self::OTP_REGENERATE_FIELD ] ); - - if ( $otp_regenerate_requested ) { - $this->focus_section = true; - } - $otp_code = ''; if ( isset( $_POST[ self::OTP_CODE_FIELD ] ) && is_string( $_POST[ self::OTP_CODE_FIELD ] ) ) { @@ -746,21 +729,8 @@ class Profile_Settings { $otp_requested = in_array( 'otp', $requested_methods, true ); $otp_should_remain_enabled = false; - if ( $otp_regenerate_requested ) { - $this->otp_manager->delete_secret( $user_id ); - $this->otp_manager->ensure_secret( $user ); - $otp_was_enabled = false; - $otp_requested = true; - add_settings_error( - 'robotstxt-2fa', - 'robotstxt-2fa-otp-reset', - __( 'A new authenticator secret is ready. Scan the QR code and confirm it with a fresh code to finish reconnecting.', 'robotstxt-2fa' ), - 'updated' - ); - } - if ( $otp_was_enabled ) { - if ( $otp_requested && ! $otp_regenerate_requested ) { + if ( $otp_requested ) { $otp_should_remain_enabled = true; } else { $this->otp_manager->delete_secret( $user_id ); @@ -865,6 +835,11 @@ class Profile_Settings { $selected_methods = array_values( array_unique( $selected_methods ) ); + // When enabling for the first time without selecting a method, default to email. + if ( $enabled && empty( $selected_methods ) && in_array( 'email', $available_keys, true ) ) { + $selected_methods[] = 'email'; + } + if ( ! $is_forced && empty( $selected_methods ) ) { $enabled = false; } diff --git a/readme.txt b/readme.txt index d8fd5ee..9d31fd0 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: security, two-factor authentication, login, otp Requires at least: 6.4 Tested up to: 7.0 Requires PHP: 8.2 -Stable tag: 0.3.0 +Stable tag: 1.0.0 License: GPLv3 or later License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -59,6 +59,17 @@ Yes. Activate the plugin at the network level. Network administrators can set an == Changelog == += 1.0.0 = + +_Release date: 2026-06-05_ + +* Fixed: Enable 2FA checkbox now defaults to email method on first activation. +* Fixed: QR code now renders correctly (data URI was stripped by esc_url). +* Fixed: Resend link shows a 60-second live countdown to prevent email flooding. +* Changed: Recovery codes section redesigned — plain list, no green notice box. +* Changed: 2FA login links now a vertical list instead of inline bullets. +* Removed: Redundant "Generate new secret" button from OTP section. + = 0.3.0 = _Release date: 2026-06-05_ diff --git a/robotstxt-2fa.php b/robotstxt-2fa.php index 052ce26..a581647 100644 --- a/robotstxt-2fa.php +++ b/robotstxt-2fa.php @@ -3,7 +3,7 @@ * Plugin Name: 2FA (by ROBOTSTXT) * Plugin URI: https://www.robotstxt.es/plugins/robotstxt-2fa/ * Description: Adds two-factor authentication to the WordPress login flow. - * Version: 0.3.0 + * Version: 1.0.0 * Author: ROBOTSTXT * Author URI: https://www.robotstxt.es/ * Text Domain: robotstxt-2fa @@ -23,7 +23,7 @@ if ( ! defined( 'ABSPATH' ) ) { } if ( ! defined( 'ROBOTSTXT_2FA_VERSION' ) ) { - define( 'ROBOTSTXT_2FA_VERSION', '0.3.0' ); + define( 'ROBOTSTXT_2FA_VERSION', '1.0.0' ); } if ( ! defined( 'ROBOTSTXT_2FA_FILE' ) ) { diff --git a/templates/.gitkeep b/templates/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/update.json b/update.json index 9e58c34..cd3b887 100644 --- a/update.json +++ b/update.json @@ -1,8 +1,8 @@ { "name": "2FA (by ROBOTSTXT)", "slug": "robotstxt-2fa", - "version": "0.3.0", - "download_url": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-2fa/releases/download/0.3.0/robotstxt-2fa-0.3.0.zip", + "version": "1.0.0", + "download_url": "https://git.robotstxt.es/ROBOTSTXT/robotstxt-2fa/releases/download/1.0.0/robotstxt-2fa-1.0.0.zip", "requires": "6.4", "requires_php": "8.2", "tested": "7.1", @@ -11,10 +11,10 @@ "author_profile": "https://www.robotstxt.es/", "homepage": "https://www.robotstxt.es/plugins/robotstxt-2fa/", "description": "Adds per-role two-factor authentication to the WordPress login flow. Supports email codes, authenticator apps (TOTP), and recovery codes.", - "changelog": "

0.3.0 - 2026-06-05

0.2.0 - 2026-06-05

", + "changelog": "

1.0.0 - 2026-06-05

", "sections": { "description": "Adds per-role two-factor authentication to the WordPress login flow. Supports email codes, authenticator apps (TOTP), and recovery codes.", - "changelog": "

0.3.0 - 2026-06-05

" + "changelog": "

1.0.0 - 2026-06-05

" }, "banners": { "low": "", diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index e12552c..e956584 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -1,9 +1,9 @@ array( 'name' => 'robotstxt/robotstxt-2fa', - 'pretty_version' => '1.0.0+no-version-set', - 'version' => '1.0.0.0', - 'reference' => null, + 'pretty_version' => 'dev-main', + 'version' => 'dev-main', + 'reference' => '4ff3019f7db5f58be0ecb3a3f1bb97bd97bdd153', 'type' => 'wordpress-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(), @@ -29,9 +29,9 @@ 'dev_requirement' => false, ), 'robotstxt/robotstxt-2fa' => array( - 'pretty_version' => '1.0.0+no-version-set', - 'version' => '1.0.0.0', - 'reference' => null, + 'pretty_version' => 'dev-main', + 'version' => 'dev-main', + 'reference' => '4ff3019f7db5f58be0ecb3a3f1bb97bd97bdd153', 'type' => 'wordpress-plugin', 'install_path' => __DIR__ . '/../../', 'aliases' => array(),