-
Notifications
You must be signed in to change notification settings - Fork 176
Alternative to #741 - Autosubmit Tweak #820
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
e17c5b3
1fada25
23b8907
698c7a5
e9b935d
4659913
18732c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -257,10 +257,10 @@ private function get_backup_code_length( $user ) { | |||||
| * | ||||||
| * @since 0.11.0 | ||||||
| * | ||||||
| * @param int $code_length Length of the backup code. Default 8. | ||||||
| * @param int $code_length Length of the backup code. Default is taken from the `two_factor_code_length` filter (which defaults to 8 if not filtered). | ||||||
| * @param WP_User $user User object. | ||||||
| */ | ||||||
| $code_length = (int) apply_filters( 'two_factor_backup_code_length', 8, $user ); | ||||||
| $code_length = (int) apply_filters( 'two_factor_backup_code_length', self::get_code_length(), $user ); | ||||||
|
|
||||||
| return $code_length; | ||||||
| } | ||||||
|
|
@@ -387,6 +387,18 @@ public function authentication_page( $user ) { | |||||
| $code_length = $this->get_backup_code_length( $user ); | ||||||
| $code_placeholder = str_repeat( 'X', $code_length ); | ||||||
|
|
||||||
| /** | ||||||
| * Filters the `digits` dataset attribute of the backup code input field on the authentication screen. | ||||||
| * | ||||||
| * To disable autosubmit, set the digits to `0` via the core method `__return_zero`. | ||||||
| * | ||||||
| * @since 0.?.0 | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * | ||||||
| * @param int $code_length The length of the backup code. | ||||||
| * @param Two_Factor_Provider $provider The two-factor provider instance. | ||||||
| */ | ||||||
| $code_length = apply_filters( 'two_factor_autosubmit_length', $code_length, $this ); | ||||||
|
|
||||||
| ?> | ||||||
| <?php | ||||||
| /** | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -142,15 +142,18 @@ public static function is_supported_for_user( $user = null ) { | |||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Generate a random eight-digit string to send out as an auth code. | ||||||
| * Generate a random string to send out as an auth code. Default is an 8 digit numeric code, but the length and characters can be customized. | ||||||
| * | ||||||
| * @since 0.1-dev | ||||||
| * | ||||||
| * @param int $length The code length. | ||||||
| * @param string|array $chars Valid auth code characters. | ||||||
| * @return string | ||||||
| */ | ||||||
| public static function get_code( $length = 8, $chars = '1234567890' ) { | ||||||
| public static function get_code( $length = null, $chars = '1234567890' ) { | ||||||
| if ( is_null( $length ) ) { | ||||||
| $length = self::get_code_length( 8, static::class ); | ||||||
| } | ||||||
| $code = ''; | ||||||
| if ( is_array( $chars ) ) { | ||||||
| $chars = implode( '', $chars ); | ||||||
|
|
@@ -161,6 +164,29 @@ public static function get_code( $length = 8, $chars = '1234567890' ) { | |||||
| return $code; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Get the code length for a provider. | ||||||
| * | ||||||
| * @since 0.?.0 | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * | ||||||
| * @param int $default Default code length if not filtered. | ||||||
| * @param string|null $provider The provider class name. Null uses the called class. | ||||||
| * @return int Number of characters. | ||||||
| */ | ||||||
| public static function get_code_length( $default = 8, $provider = null ) { | ||||||
| /** | ||||||
| * Filter the default code length for a provider. | ||||||
| * | ||||||
| * @since 0.?.0 | ||||||
masteradhoc marked this conversation as resolved.
Show resolved
Hide resolved
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| * | ||||||
| * @param int $code_length Length of the code. Default 8. | ||||||
| * @param string $provider The provider class name. | ||||||
| */ | ||||||
| $code_length = (int) apply_filters( 'two_factor_code_length', $default, $provider ?: static::class ); | ||||||
|
|
||||||
| return $code_length; | ||||||
| } | ||||||
georgestephanis marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| /** | ||||||
| * Sanitizes a numeric code to be used as an auth code. | ||||||
| * | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -720,11 +720,11 @@ public static function pack64( int $value ): string { | |||||||||||||||||
| if ( 8 === PHP_INT_SIZE ) { | ||||||||||||||||||
| return pack( 'J', $value ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // 32-bit PHP fallback | ||||||||||||||||||
| $higher = ( $value >> 32 ) & 0xFFFFFFFF; | ||||||||||||||||||
| $lower = $value & 0xFFFFFFFF; | ||||||||||||||||||
|
|
||||||||||||||||||
| return pack( 'NN', $higher, $lower ); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -832,6 +832,10 @@ public function is_available_for_user( $user ) { | |||||||||||||||||
| * @codeCoverageIgnore | ||||||||||||||||||
| */ | ||||||||||||||||||
| public function authentication_page( $user ) { | ||||||||||||||||||
|
|
||||||||||||||||||
| /** This filter is documented in providers/class-two-factor-backup-codes.php */ | ||||||||||||||||||
| $code_length = apply_filters( 'two_factor_autosubmit_length', self::DEFAULT_DIGIT_COUNT, $this ); | ||||||||||||||||||
|
|
||||||||||||||||||
| require_once ABSPATH . '/wp-admin/includes/template.php'; | ||||||||||||||||||
| ?> | ||||||||||||||||||
| <?php | ||||||||||||||||||
|
|
@@ -847,7 +851,7 @@ public function authentication_page( $user ) { | |||||||||||||||||
| ?> | ||||||||||||||||||
| <p> | ||||||||||||||||||
| <label for="authcode"><?php esc_html_e( 'Authentication Code:', 'two-factor' ); ?></label> | ||||||||||||||||||
| <input type="text" inputmode="numeric" name="authcode" id="authcode" class="input authcode" value="" size="20" pattern="[0-9 ]*" placeholder="123 456" autocomplete="one-time-code" data-digits="<?php echo esc_attr( self::DEFAULT_DIGIT_COUNT ); ?>" /> | ||||||||||||||||||
| <input type="text" inputmode="numeric" name="authcode" id="authcode" class="input authcode" value="" size="20" pattern="[0-9 ]*" placeholder="123 456" autocomplete="one-time-code" data-digits="<?php echo esc_attr( $code_length ); ?>" /> | ||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think we probably should work a bit on the placeholder as well. the space in between 3 and 4 doesnt make sense. additionally based on the code_length we could also generate this also dynamically. BTW the spacing after entering the numbers manually i dont feel its a great UX - what do you think?: two-factor/providers/js/two-factor-login-authcode.js Lines 16 to 21 in cbc73d5
|
||||||||||||||||||
| </p> | ||||||||||||||||||
| <?php | ||||||||||||||||||
| /** This action is documented in providers/class-two-factor-backup-codes.php */ | ||||||||||||||||||
|
|
||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.