Ticket #4470: password-strength-meter2.diff
| File password-strength-meter2.diff, 7.3 KB (added by JDTrower, 4 years ago) |
|---|
-
wp-admin/js/passwordStrengthMeter.js
1 // Password strength meter 2 // This jQuery plugin is written by firas kassem [2007.04.05] 3 // Firas Kassem phiras.wordpress.com || phiras at gmail {dot} com 4 // for more information : http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/ 5 6 var shortPass = 'Too short' 7 var badPass = 'Bad' 8 var goodPass = 'Good' 9 var strongPass = 'Strong' 10 11 12 13 function passwordStrength(password,username) 14 { 15 score = 0 16 17 //password < 4 18 if (password.length < 4 ) { return shortPass } 19 20 //password == username 21 if (password.toLowerCase()==username.toLowerCase()) return badPass 22 23 //password length 24 score += password.length * 4 25 score += ( checkRepetition(1,password).length - password.length ) * 1 26 score += ( checkRepetition(2,password).length - password.length ) * 1 27 score += ( checkRepetition(3,password).length - password.length ) * 1 28 score += ( checkRepetition(4,password).length - password.length ) * 1 29 30 //password has 3 numbers 31 if (password.match(/(.*[0-9].*[0-9].*[0-9])/)) score += 5 32 33 //password has 2 sybols 34 if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5 35 36 //password has Upper and Lower chars 37 if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) score += 10 38 39 //password has number and chars 40 if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) score += 15 41 // 42 //password has number and symbol 43 if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/)) score += 15 44 45 //password has char and symbol 46 if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/)) score += 15 47 48 //password is just a nubers or chars 49 if (password.match(/^\w+$/) || password.match(/^\d+$/) ) score -= 10 50 51 //verifing 0 < score < 100 52 if ( score < 0 ) score = 0 53 if ( score > 100 ) score = 100 54 55 if (score < 34 ) return badPass 56 if (score < 68 ) return goodPass 57 return strongPass 58 } 59 60 61 // checkRepetition(1,'aaaaaaabcbc') = 'abcbc' 62 // checkRepetition(2,'aaaaaaabcbc') = 'aabc' 63 // checkRepetition(2,'aaaaaaabcdbcd') = 'aabcd' 64 65 function checkRepetition(pLen,str) { 66 res = "" 67 for ( i=0; i<str.length ; i++ ) { 68 repeated=true 69 for (j=0;j < pLen && (j+i+pLen) < str.length;j++) 70 repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen)) 71 if (j<pLen) repeated=false 72 if (repeated) { 73 i+=pLen-1 74 repeated=false 75 } 76 else { 77 res+=str.charAt(i) 78 } 79 } 80 return res 81 } -
wp-admin/profile.php
1 1 <?php 2 2 require_once('admin.php'); 3 3 4 function profile_js ( ) { 5 ?> 6 <script type="text/javascript"> 7 function check_pass_strength ( ) { 8 9 var pass = jQuery('#pass1').val(); 10 var user = jQuery('#user_login').val(); 11 12 // get the result as an object, i'm tired of typing it 13 var res = jQuery('#pass-strength-result'); 14 15 var strength = passwordStrength(pass, user); 16 17 jQuery(res).removeClass('short bad good strong'); 18 19 if ( strength == 'Bad' ) { 20 jQuery(res).addClass('bad'); 21 jQuery(res).html( pwsL10n.bad ); 22 } 23 else if ( strength == 'Good' ) { 24 jQuery(res).addClass('good'); 25 jQuery(res).html( pwsL10n.good ); 26 } 27 else if ( strength == 'Strong' ) { 28 jQuery(res).addClass('strong'); 29 jQuery(res).html( pwsL10n.strong ); 30 } 31 else { 32 // this catches 'Too short' and the off chance anything else comes along 33 jQuery(res).addClass('short'); 34 jQuery(res).html( pwsL10n.short ); 35 } 36 37 } 38 39 jQuery(document).ready( function() { jQuery('#pass1').keyup( check_pass_strength ) } ); 40 </script> 41 <?php 42 } 43 44 add_action('admin_head', 'profile_js'); 45 46 wp_enqueue_script('jquery'); 47 wp_enqueue_script('password-strength-meter'); 48 4 49 $title = __('Profile'); 5 50 6 51 if ( current_user_can('edit_users') ) … … 42 87 <fieldset id="information"> 43 88 <legend><?php _e('Name'); ?></legend> 44 89 <p><label><?php _e('Username: (no editing)'); ?><br /> 45 <input type="text" name="user_login" value="<?php echo $profileuser->user_login; ?>" disabled="disabled" />90 <input type="text" name="user_login" id="user_login" value="<?php echo $profileuser->user_login; ?>" disabled="disabled" /> 46 91 </label></p> 47 92 48 93 <p><label><?php _e('First name:') ?><br /> … … 114 159 <p><label><?php _e('Type it one more time:'); ?><br /> 115 160 <input type="password" name="pass2" id="pass2" size="16" value="" /> 116 161 </label></p> 162 <p><strong><?php _e('Password Strength:'); ?></strong></p> 163 <div id="pass-strength-result"><?php _e('Too short'); ?></div> 164 <!--[if IE 6]><div id="pass-strength-iesucks"><?php _e("If you weren’t using this sucky IE6, there would be pretty colors... and cookies!"); ?></div><![endif]--> 165 <p><?php _e('Hint: Use upper and lower case characters, numbers and symbols like !"£$%^&( in your password.'); ?></p> 117 166 </fieldset> 118 167 <?php endif; ?> 119 168 -
wp-admin/wp-admin.css
1355 1355 } 1356 1356 #update-nag a:link, .plugin-update a:link { 1357 1357 color: #036; 1358 } 1359 No newline at end of file 1358 } 1359 1360 #pass-strength-result { 1361 padding: 3px 5px 3px 5px; 1362 margin-top: 3px; 1363 text-align: center; 1364 background-color: #e3e3e3; 1365 border: 1px solid #000000; 1366 } 1367 1368 #pass-strength-result.short { 1369 background-color: #e3e3e3; 1370 border: 1px solid #000000; 1371 } 1372 1373 #pass-strength-result.bad { 1374 background-color: #ffeff7; 1375 border: 1px solid #cc6699; 1376 } 1377 1378 #pass-strength-result.good { 1379 background-color: #effff4; 1380 border: 1px solid #66cc87; 1381 } 1382 1383 #pass-strength-result.strong { 1384 background-color: #59ef86; 1385 border: 1px solid #319f52; 1386 } 1387 1388 #pass-strength-iesucks { 1389 font-size: 8pt; 1390 text-align: center; 1391 } 1392 No newline at end of file -
wp-includes/script-loader.php
117 117 ) ); 118 118 $this->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' ); 119 119 $this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' ); 120 $this->add( 'password-strength-meter', '/wp-admin/js/passwordStrengthMeter.js', array('jquery'), '20070405' ); 121 $this->localize( 'password-strength-meter', 'pwsL10n', array( 122 'short' => __('Too short'), 123 'bad' => __('Bad'), 124 'good' => __('Good'), 125 'strong' => __('Strong') 126 ) ); 120 127 $this->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists'), '20071104' ); 121 128 $this->add( 'admin-posts', '/wp-admin/js/edit-posts.js', array('wp-lists'), '20071023' ); 122 129 $this->add( 'admin-users', '/wp-admin/js/users.js', array('wp-lists'), '20070823' );
