diff --git a/providers/class-two-factor-backup-codes.php b/providers/class-two-factor-backup-codes.php index 12601d5c..89389238 100644 --- a/providers/class-two-factor-backup-codes.php +++ b/providers/class-two-factor-backup-codes.php @@ -239,8 +239,16 @@ public function generate_codes( $user, $args = '' ) { $codes_hashed = (array) get_user_meta( $user->ID, self::BACKUP_CODES_META_KEY, true ); } + /** + * Customize the character count of the backup codes. + * + * @var int $code_length Length of the backup code. + * @var WP_User $user User object. + */ + $code_length = (int) apply_filters( 'two_factor_backup_code_length', 8, $user ); + for ( $i = 0; $i < $num_codes; $i++ ) { - $code = $this->get_code(); + $code = $this->get_code( $code_length ); $codes_hashed[] = wp_hash_password( $code ); $codes[] = $code; unset( $code ); diff --git a/readme.txt b/readme.txt index 07cd5777..d0853539 100644 --- a/readme.txt +++ b/readme.txt @@ -29,6 +29,7 @@ Here is a list of action and filter hooks provided by the plugin: - `two_factor_user_authenticated` action which receives the logged in `WP_User` object as the first argument for determining the logged in user right after the authentication workflow. - `two_factor_token_ttl` filter overrides the time interval in seconds that an email token is considered after generation. Accepts the time in seconds as the first argument and the ID of the `WP_User` object being authenticated. - `two_factor_token_length` filter overrides the default 8 character count for email tokens. +- `two_factor_backup_code_length` filter overrides the default 8 character count for backup codes. Providers the `WP_User` of the associated user as the second argument. == Frequently Asked Questions ==