Skip to content

Commit

Permalink
Avoid confusion about the token type
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd committed Jan 9, 2025
1 parent 61a7489 commit 01cfb60
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion providers/class-two-factor-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function get_alternative_provider_label() {
* @return string
*/
public function generate_token( $user_id ) {
$token_length = (int) apply_filters( 'two_factor_token_length', 8 );
$token_length = (int) apply_filters( 'two_factor_email_token_length', 8 );

$token = $this->get_code( $token_length );

Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Here is a list of action and filter hooks provided by the plugin:
- `two_factor_enabled_providers_for_user` filter overrides the list of two-factor providers enabled for a user. First argument is an array of enabled provider classnames as values, the second argument is the user ID.
- `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_email_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 ==
Expand Down
4 changes: 2 additions & 2 deletions tests/providers/class-two-factor-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public function test_custom_token_length() {
$default_token = $this->provider->generate_token( $user_id );

add_filter(
'two_factor_token_length',
'two_factor_email_token_length',
function() {
return 15;
}
Expand All @@ -369,7 +369,7 @@ function() {
$this->assertNotEquals( strlen( $default_token ), strlen( $custom_token ), 'Token length is different due to filter' );
$this->assertEquals( 15, strlen( $custom_token ), 'Token length matches the filter value' );

remove_all_filters( 'two_factor_token_length' );
remove_all_filters( 'two_factor_email_token_length' );
}

}

0 comments on commit 01cfb60

Please sign in to comment.