From 1064d920fb4d4a99f1311b752081eed997cf5eb0 Mon Sep 17 00:00:00 2001 From: Christian Jacobs Date: Sat, 11 Sep 2021 17:53:12 +0200 Subject: [PATCH 1/3] Add filter two_factor_email_token_length The length of the email token (code) can be set with filter two_factor_email_token_length The default is 8, like before --- providers/class-two-factor-email.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/providers/class-two-factor-email.php b/providers/class-two-factor-email.php index 1cd004bf..82062298 100644 --- a/providers/class-two-factor-email.php +++ b/providers/class-two-factor-email.php @@ -77,7 +77,7 @@ public function get_label() { * @return string */ public function generate_token( $user_id ) { - $token = $this->get_code(); + $token = $this->get_code($this->get_token_length()); update_user_meta( $user_id, self::TOKEN_META_KEY_TIMESTAMP, time() ); update_user_meta( $user_id, self::TOKEN_META_KEY, wp_hash( $token ) ); @@ -157,6 +157,17 @@ public function user_token_ttl( $user_id ) { return (int) apply_filters( 'two_factor_token_ttl', $token_ttl, $user_id ); } + /** + * Return the number of digits of the token. + * + * @return integer + */ + + public function get_token_length() { + $token_length = 8; + return (int) apply_filters( 'two_factor_email_token_length', $token_length); + } + /** * Get the authentication token for the user. * From a9bfb349fa71947c7fe240523b5e126bd334c45e Mon Sep 17 00:00:00 2001 From: Christian Jacobs Date: Thu, 24 Mar 2022 20:52:12 +0100 Subject: [PATCH 2/3] Fix whitespace around parameters --- providers/class-two-factor-email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/providers/class-two-factor-email.php b/providers/class-two-factor-email.php index 82062298..18939c05 100644 --- a/providers/class-two-factor-email.php +++ b/providers/class-two-factor-email.php @@ -77,7 +77,7 @@ public function get_label() { * @return string */ public function generate_token( $user_id ) { - $token = $this->get_code($this->get_token_length()); + $token = $this->get_code( $this->get_token_length() ); update_user_meta( $user_id, self::TOKEN_META_KEY_TIMESTAMP, time() ); update_user_meta( $user_id, self::TOKEN_META_KEY, wp_hash( $token ) ); @@ -165,7 +165,7 @@ public function user_token_ttl( $user_id ) { public function get_token_length() { $token_length = 8; - return (int) apply_filters( 'two_factor_email_token_length', $token_length); + return (int) apply_filters( 'two_factor_email_token_length', $token_length ); } /** From 0caafb0bd247337d772f3f8d7eb317617bb058a1 Mon Sep 17 00:00:00 2001 From: Christian Jacobs Date: Thu, 24 Mar 2022 20:54:00 +0100 Subject: [PATCH 3/3] Add new filter hook description to readme --- readme.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.txt b/readme.txt index d6254516..ca904746 100644 --- a/readme.txt +++ b/readme.txt @@ -28,6 +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_email_token_length` filter overrides default number of digits (8) of the email token. == Screenshots ==