Changeset 837308
- Timestamp:
- 01/12/2014 07:03:49 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
google-authenticator/trunk/google-authenticator.php
r834053 r837308 5 5 Description: Two-Factor Authentication for WordPress using the Android/iPhone/Blackberry app as One Time Password generator. 6 6 Author: Henrik Schack 7 Version: 0.4 67 Version: 0.47 8 8 Author URI: http://henrik.schack.dk/ 9 9 Compatibility: WordPress 3.8 … … 23 23 Thanks to Kimmo Suominen for fixing the iPhone description issue. 24 24 Thanks to Alex Concha for some security tips. 25 Thanks to Sébastien Prunier for his Spanish and French translations. 25 26 26 27 ---------------------------------------------------------------------------- … … 65 66 add_filter( 'authenticate', array( $this, 'check_otp' ), 50, 3 ); 66 67 67 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) 68 if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { 68 69 add_action( 'wp_ajax_GoogleAuthenticator_action', array( $this, 'ajax_callback' ) ); 70 } 69 71 70 72 add_action( 'personal_options_update', array( $this, 'personal_options_update' ) ); … … 73 75 add_action( 'edit_user_profile_update', array( $this, 'edit_user_profile_update' ) ); 74 76 77 add_action('admin_enqueue_scripts', array($this, 'add_qrcode_script')); 78 75 79 load_plugin_textdomain( 'google-authenticator', false, basename( dirname( __FILE__ ) ) . '/lang' ); 76 80 } 81 77 82 78 83 /** … … 123 128 // last successful login. 124 129 if ( $lasttimeslot >= ($tm+$i) ) { 130 error_log("Google Authenticator plugin: Man-in-the-middle attack detected (Could also be 2 legit login attempts within the same 30 second period)"); 125 131 return false; 126 132 } 127 133 // Return timeslot in which login happened. 128 134 return $tm+$i; 129 } 135 } 130 136 } 131 137 return false; … … 146 152 } 147 153 154 /** 155 * Add the script to generate QR codes. 156 */ 157 function add_qrcode_script() { 158 wp_enqueue_script('jquery'); 159 wp_register_script('qrcode_script', plugins_url('jquery.qrcode.min.js', __FILE__),array("jquery")); 160 wp_enqueue_script('qrcode_script'); 161 } 148 162 149 163 /** … … 292 306 echo "<input name=\"GA_secret\" id=\"GA_secret\" value=\"{$GA_secret}\" readonly=\"readonly\" type=\"text\" size=\"25\" />"; 293 307 echo "<input name=\"GA_newsecret\" id=\"GA_newsecret\" value=\"".__("Create new secret",'google-authenticator')."\" type=\"button\" class=\"button\" />"; 294 echo "<input name=\"show_qr\" id=\"show_qr\" value=\"".__("Show/Hide QR code",'google-authenticator')."\" type=\"button\" class=\"button\" onclick=\"Show QRCodeAfterWarning();\" />";308 echo "<input name=\"show_qr\" id=\"show_qr\" value=\"".__("Show/Hide QR code",'google-authenticator')."\" type=\"button\" class=\"button\" onclick=\"ShowOrHideQRCode();\" />"; 295 309 echo "</td>\n"; 296 310 echo "</tr>\n"; … … 299 313 echo "<th></th>\n"; 300 314 echo "<td><div id=\"GA_QR_INFO\" style=\"display: none\" >"; 301 echo "< img id=\"GA_QRCODE\" src=\"\" alt=\"QR Code\"/>";315 echo "<div id=\"GA_QRCODE\"/></div>"; 302 316 303 317 echo '<span class="description"><br/> ' . __( 'Scan this with the Google Authenticator app.', 'google-authenticator' ) . '</span>'; … … 317 331 echo "<input name=\"GA_password\" id=\"GA_password\" readonly=\"readonly\" value=\"".$GA_password."\" type=\"text\" size=\"25\" />"; 318 332 echo "<input name=\"GA_createpassword\" id=\"GA_createpassword\" value=\"".__("Create new password",'google-authenticator')."\" type=\"button\" class=\"button\" />"; 319 echo "<span class=\"description\" id=\"GA_passworddesc\"> ".__(' Password is not stored in cleartext, this is your only chance to see it.','google-authenticator')."</span>\n";333 echo "<span class=\"description\" id=\"GA_passworddesc\"> ".__(' Password is not stored in cleartext, this is your only chance to see it.','google-authenticator')."</span>\n"; 320 334 echo "</td>\n"; 321 335 echo "</tr>\n"; 322 336 } 323 324 337 325 338 echo "</tbody></table>\n"; … … 327 340 echo "var GAnonce='".wp_create_nonce('GoogleAuthenticatoraction')."';\n"; 328 341 329 echo "var qrcodewarningtext = '";330 echo __( "WARNING:\\n\\nShowing the QR code will use the Google Chart API to do so.\\nIf you do not trust Google, please press Cancel and enter the code manually.",'google-authenticator' );331 echo "';\n";332 333 342 echo <<<ENDOFJS 334 var pwdata;343 //Create new secret and display it 335 344 jQuery('#GA_newsecret').bind('click', function() { 345 // Remove existing QRCode 346 jQuery('#GA_QRCODE').html(""); 336 347 var data=new Object(); 337 348 data['action'] = 'GoogleAuthenticator_action'; … … 339 350 jQuery.post(ajaxurl, data, function(response) { 340 351 jQuery('#GA_secret').val(response['new-secret']); 341 chl=escape("otpauth://totp/"+jQuery('#GA_description').val()+"?secret="+jQuery('#GA_secret').val()); 342 qrcodeurl="https://chart.googleapis.com/chart?cht=qr&chs=300x300&chld=H|0&chl="+chl; 343 jQuery('#GA_QRCODE').attr('src',qrcodeurl); 344 jQuery('#GA_QR_INFO').show('slow'); 352 var qrcode="otpauth://totp/WordPress:"+escape(jQuery('#GA_description').val())+"?secret="+jQuery('#GA_secret').val()+"&issuer=WordPress"; 353 jQuery('#GA_QRCODE').qrcode(qrcode); 354 jQuery('#GA_QR_INFO').show('slow'); 345 355 }); 346 356 }); 347 357 358 // If the user starts modifying the description, hide the qrcode 348 359 jQuery('#GA_description').bind('focus blur change keyup', function() { 349 // Only update QRCode if it's alreadyvisible360 // Only remove QR Code if it's visible 350 361 if (jQuery('#GA_QR_INFO').is(':visible')) { 351 chl=escape("otpauth://totp/"+jQuery('#GA_description').val()+"?secret="+jQuery('#GA_secret').val()); 352 qrcodeurl="https://chart.googleapis.com/chart?cht=qr&chs=300x300&chld=H|0&chl="+chl; 353 jQuery('#GA_QRCODE').attr('src',qrcodeurl); 362 jQuery('#GA_QR_INFO').hide('slow'); 363 jQuery('#GA_QRCODE').html(""); 354 364 } 355 365 }); 356 366 367 // Create new app password 357 368 jQuery('#GA_createpassword').bind('click',function() { 358 369 var data=new Object(); … … 386 397 } 387 398 388 function Show QRCodeAfterWarning() {399 function ShowOrHideQRCode() { 389 400 if (jQuery('#GA_QR_INFO').is(':hidden')) { 390 if ( confirm(qrcodewarningtext) ) { 391 chl=escape("otpauth://totp/"+jQuery('#GA_description').val()+"?secret="+jQuery('#GA_secret').val()); 392 qrcodeurl="https://chart.googleapis.com/chart?cht=qr&chs=300x300&chld=H|0&chl="+chl; 393 jQuery('#GA_QRCODE').attr('src',qrcodeurl); 394 jQuery('#GA_QR_INFO').show('slow'); 395 } 401 var qrcode="otpauth://totp/WordPress:"+escape(jQuery('#GA_description').val())+"?secret="+jQuery('#GA_secret').val()+"&issuer=WordPress"; 402 jQuery('#GA_QRCODE').qrcode(qrcode); 403 jQuery('#GA_QR_INFO').show('slow'); 396 404 } else { 397 405 jQuery('#GA_QR_INFO').hide('slow'); 406 jQuery('#GA_QRCODE').html(""); 398 407 } 399 408 } … … 517 526 global $user_id; 518 527 519 // Some AJAX security 528 // Some AJAX security. 520 529 check_ajax_referer( 'GoogleAuthenticatoraction', 'nonce' ); 521 530 522 // Create new secret , using the users password hash as input for further hashing531 // Create new secret. 523 532 $secret = $this->create_secret(); 524 533
Note: See TracChangeset
for help on using the changeset viewer.