label; } /** * @return string */ public function get_login_label() { return __( 'TOTP Authentication', 'wpdef' ); } /** * @return string */ public function get_user_label() { return __( 'TOTP', 'wpdef' ); } /** * Get the desc of the provider. * * @return string */ public function get_description() { return $this->description; } public function authentication_form() { ?>
get_login_label(); ?>
get_model()->app_text ); ?>
'Google Authenticator', 'microsoft-authenticator' => 'Microsoft Authenticator', 'authy' => 'Authy', ); } /** * @param \WP_User $user */ public function init_provider( $user ) { $is_on = $this->is_available_for_user( $user ); $this->label = $is_on ? sprintf( /* translators: %s: style class */ __( '', 'wpdef' ), $this->get_component()->is_checked_enabled_provider_by_slug( $user, self::$slug ) ? '' : ' disabled' ) : ''; $this->description = $is_on ? __( 'TOTP Authentication method is active for this site', 'wpdef' ) : __( 'Use an authenticator app to sign in with a separate passcode.', 'wpdef' ); } /** * Display auth method. * * @param WP_User $user */ public function user_options( $user ) { if ( ! wp_script_is( 'clipboard', 'enqueued' ) ) { wp_enqueue_script( 'clipboard' ); } $model = $this->get_model(); $service = $this->get_component(); $default_values = $model->get_default_values(); $is_on = $this->is_available_for_user($user); if ( $is_on ) { $this->get_controller()->render_partial( 'two-fa/providers/totp-enabled', array( 'url' => $this->get_url( 'disable_totp' ), ) ); } else { $this->get_controller()->render_partial( 'two-fa/providers/totp-disabled', array( 'url' => $this->get_url( 'verify_otp_for_enabling' ), 'default_message' => $default_values['message'], 'auth_apps' => $this->get_auth_apps(), 'user' => $user, 'secret_key' => $service::get_user_secret(), 'class' => $service->is_checked_enabled_provider_by_slug( $user, self::$slug ) ? '' : 'hidden', ) ); } } /** * Generate a QR code for apps can use. Apps from get_auth_apps(). * * @param string $secret_key */ public static function generate_qr_code( $secret_key ) { $settings = new \WP_Defender\Model\Setting\Two_Fa(); $issuer = $settings->app_title; $user = wp_get_current_user(); $chl = ( 'otpauth://totp/' . rawurlencode( $issuer ) . ':' . rawurlencode( $user->user_email ) . '?secret=' . $secret_key . '&issuer=' . rawurlencode( $issuer ) ); require_once defender_path( 'src/extra/phpqrcode/phpqrcode.php' ); \QRcode::svg( $chl, false, QR_ECLEVEL_L, 4 ); } /** * Whether this 2FA provider is configured and available for the user specified. * * @param WP_User $user WP_User object of the logged-in user. * * @return boolean */ public function is_available_for_user( $user ) { return (bool) get_user_meta( $user->ID, 'defenderAuthOn', true ); } /** * @param \WP_User $user * * @return bool|\WP_Error */ public function validate_authentication( $user ) { $otp = HTTP::post( 'otp' ); if ( empty( $otp ) ) { return new \WP_Error( 'opt_fail', __( 'Whoops, the passcode you entered was incorrect or expired.', 'wpdef' ) ); } return $this->get_component()->verify_otp( $otp, $user ); } }