Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ public static function is_api_request() {
*
* @since 0.2.0
*
* @param WP_User $user WP_User object of the logged-in user.
* @param WP_User|false $user WP_User object of the logged-in user.
*/
public static function show_two_factor_login( $user ) {
if ( ! $user ) {
Expand Down Expand Up @@ -1804,9 +1804,9 @@ public static function _login_form_revalidate_2fa( $nonce = '', $provider = '',
*
* @since 0.9.0
*
* @param object $provider The Two Factor Provider.
* @param WP_User $user The user being authenticated.
* @param bool $is_post_request Whether the request is a POST request.
* @param object|null $provider The Two Factor Provider.
* @param WP_User $user The user being authenticated.
* @param bool $is_post_request Whether the request is a POST request.
Comment on lines +1807 to +1809
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PHPDoc parameter alignment spacing is incorrect.

Suggested change
* @param object|null $provider The Two Factor Provider.
* @param WP_User $user The user being authenticated.
* @param bool $is_post_request Whether the request is a POST request.
* @param object|null $provider The Two Factor Provider.
* @param WP_User $user The user being authenticated.
* @param bool $is_post_request Whether the request is a POST request.

* @return false|WP_Error|true WP_Error when an error occurs, true when the user is authenticated, false if no action occurred.
*/
public static function process_provider( $provider, $user, $is_post_request ) {
Expand Down
18 changes: 13 additions & 5 deletions providers/class-two-factor-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public function generate_and_email_token( $user ) {
*
* @since 0.1-dev
*
* @param WP_User $user WP_User object of the logged-in user.
* @param WP_User|false $user WP_User object of the logged-in user.
*/
public function authentication_page( $user ) {
if ( ! $user ) {
Expand Down Expand Up @@ -384,11 +384,15 @@ public function authentication_page( $user ) {
*
* @since 0.2.0
*
* @param WP_User $user WP_User object of the logged-in user.
* @param WP_User|false $user WP_User object of the logged-in user.
* @return boolean
*/
public function pre_process_authentication( $user ) {
if ( isset( $user->ID ) && isset( $_REQUEST[ self::INPUT_NAME_RESEND_CODE ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- non-distructive option that relies on user state.
if ( ! $user ) {
return false;
}

if ( isset( $_REQUEST[ self::INPUT_NAME_RESEND_CODE ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- non-destructive option that relies on user state.
$this->generate_and_email_token( $user );
return true;
}
Expand All @@ -401,12 +405,16 @@ public function pre_process_authentication( $user ) {
*
* @since 0.1-dev
*
* @param WP_User $user WP_User object of the logged-in user.
* @param WP_User|false $user WP_User object of the logged-in user.
* @return boolean
*/
public function validate_authentication( $user ) {
if ( ! $user ) {
return false;
}

$code = $this->sanitize_code_from_request( 'two-factor-email-code' );
if ( ! isset( $user->ID ) || ! $code ) {
Comment thread
masteradhoc marked this conversation as resolved.
if ( ! $code ) {
Comment thread
aslamdoctor marked this conversation as resolved.
return false;
}

Expand Down
12 changes: 6 additions & 6 deletions providers/class-two-factor-totp.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ public static function generate_qr_code_url( $user, $secret_key ) {
* @codeCoverageIgnore
*/
public function user_two_factor_options( $user ) {
Comment thread
masteradhoc marked this conversation as resolved.
if ( ! isset( $user->ID ) ) {
return;
}
if ( ! ( $user instanceof WP_User ) ) {
return;
}

$key = $this->get_user_totp_key( $user->ID );

Expand Down Expand Up @@ -662,11 +662,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 );
}

Expand Down Expand Up @@ -825,7 +825,7 @@ public static function base32_encode( $input ) {
$base32_string = '';

foreach ( $five_bit_sections as $five_bit_section ) {
$base32_string .= self::$base_32_chars[ base_convert( str_pad( $five_bit_section, 5, '0' ), 2, 10 ) ];
$base32_string .= self::$base_32_chars[ (int) base_convert( str_pad( $five_bit_section, 5, '0' ), 2, 10 ) ];
}

return $base32_string;
Expand Down
18 changes: 8 additions & 10 deletions two-factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@
* Network: True
*/

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
if ( ! defined( 'TWO_FACTOR_DIR' ) ) {
define( 'TWO_FACTOR_DIR', __DIR__ . '/' );
}

/**
* Shortcut constant to the path of this file.
*/
define( 'TWO_FACTOR_DIR', plugin_dir_path( __FILE__ ) );
if ( ! defined( 'TWO_FACTOR_VERSION' ) ) {
define( 'TWO_FACTOR_VERSION', '0.15.0' );
}

/**
* Version of the plugin.
*/
define( 'TWO_FACTOR_VERSION', '0.16.0' );
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

/**
* Include the base class here, so that other plugins can also extend it.
Expand Down
Loading