\n"; echo "\t\t\n"; echo "\t
\n"; } /** * Disable autocomplete on Google Authenticator code input field. */ function loginfooter() { echo "\n\n"; } /** * Login form handling. * Check Google Authenticator verification code, if user has been setup to do so. * @param wordpressuser * @return user/loginstatus */ function check_otp( $user, $username = '', $password = '' ) { // Store result of loginprocess, so far. $userstate = $user; // Get information on user, we need this in case an app password has been enabled, // since the $user var only contain an error at this point in the login flow. $user = get_userdatabylogin( $username ); // Does the user have the Google Authenticator enabled ? if ( trim(get_user_option( 'googleauthenticator_enabled', $user->ID ) ) == 'enabled' ) { // Get the users secret $GA_secret = trim( get_user_option( 'googleauthenticator_secret', $user->ID ) ); // Figure out if user is using relaxed mode ? $GA_relaxedmode = trim( get_user_option( 'googleauthenticator_relaxedmode', $user->ID ) ); // Get the verification code entered by the user trying to login $otp = trim( $_POST[ 'googleotp' ] ); // Valid code ? if ( $this->verify( $GA_secret, $otp, $GA_relaxedmode ) ) { return $userstate; } else { // No, lets see if an app password is enabled, and this is an XMLRPC / APP login ? if ( trim( get_user_option( 'googleauthenticator_pwdenabled', $user->ID ) ) == 'enabled' && ( defined('XMLRPC_REQUEST') || defined('APP_REQUEST') ) ) { $GA_passwords = json_decode( get_user_option( 'googleauthenticator_passwords', $user->ID ) ); $passwordsha1 = trim($GA_passwords->{'password'} ); $usersha1 = sha1( strtoupper( str_replace( ' ', '', $password ) ) ); if ( $passwordsha1 == $usersha1 ) { return new WP_User( $user->ID ); } else { // Wrong XMLRPC/APP password ! return new WP_Error( 'invalid_google_authenticator_password', __( 'ERROR: The Google Authenticator password is incorrect.', 'google-authenticator' ) ); } } else { return new WP_Error( 'invalid_google_authenticator_token', __( 'ERROR: The Google Authenticator code is incorrect or has expired.', 'google-authenticator' ) ); } } } // Google Authenticator isn't enabled for this account, // just resume normal authentication. return $userstate; } /** * Extend personal profile page with Google Authenticator settings. */ function profile_personal_options() { global $user_id, $is_profile_page; // If editing of Google Authenticator settings has been disabled, just return $GA_hidefromuser = trim( get_user_option( 'googleauthenticator_hidefromuser', $user_id ) ); if ( $GA_hidefromuser == 'enabled') return; $GA_secret = trim( get_user_option( 'googleauthenticator_secret', $user_id ) ); $GA_enabled = trim( get_user_option( 'googleauthenticator_enabled', $user_id ) ); $GA_relaxedmode = trim( get_user_option( 'googleauthenticator_relaxedmode', $user_id ) ); $GA_description = trim( get_user_option( 'googleauthenticator_description', $user_id ) ); $GA_pwdenabled = trim( get_user_option( 'googleauthenticator_pwdenabled', $user_id ) ); $GA_password = trim( get_user_option( 'googleauthenticator_passwords', $user_id ) ); // We dont store the generated app password in cleartext so there is no point in trying // to show the user anything except from the fact that a password exists. if ( $GA_password != '' ) { $GA_password = "XXXX XXXX XXXX XXXX"; } // In case the user has no secret ready (new install), we create one. if ( '' == $GA_secret ) { $GA_secret = $this->create_secret(); } // Use "WordPress Blog" as default description if ( '' == $GA_description ) { $GA_description = __( 'WordPressBlog', 'google-authenticator' ); } echo "To enable Google Authenticator:
'; echo 'Important: You need to make sure you scan the QR code before logging out of your site.
'; echo 'If you set Google Authenticator to "Active" without scanning the QR code then you will be locked out of your site.
'; echo '| ".__( 'Active', 'google-authenticator' )." | \n"; echo "\n"; echo "\n"; echo " | \n"; echo "
|---|---|
| ".__( 'Relaxed mode', 'google-authenticator' )." | \n"; echo "\n"; echo "".__(' Relaxed mode allows for more time drifting on your phone clock (±4 min).','google-authenticator')."\n"; echo " | \n"; echo "
| \n"; echo " | ".__(' Description that you\'ll see in the Google Authenticator app on your phone.','google-authenticator')." | \n";
echo "
| \n"; echo " | \n"; echo ""; echo ""; echo ""; echo " | \n"; echo "
| \n"; echo " | ";
echo " ' . __( 'Scan this with the Google Authenticator app.', 'google-authenticator' ) . ''; echo " | \n";
echo "
| ".__( 'Enable App password', 'google-authenticator' )." | \n"; echo "\n"; echo "".__(' Enabling an App password will decrease your overall login security.','google-authenticator')."\n"; echo " | \n"; echo "
| \n"; echo " | \n"; echo ""; echo ""; echo "".__(' Password is not stored in cleartext, this is your only chance to see it.','google-authenticator')."\n"; echo " | \n"; echo "
| ".__('Hide settings from user','google-authenticator')." | \n"; echo "\n";
echo " \n";
echo " | \n";
echo "
|---|---|
| ".__('Active','google-authenticator')." | \n"; echo "\n";
echo " \n";
echo " | \n";
echo "