Ticket #4470: password-strength-meter.diff
| File password-strength-meter.diff, 7.2 kB (added by MellerTime, 1 year ago) |
|---|
-
wp-admin/js/passwordStrengthMeter.js
old new 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
old new 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
old new 1337 1337 margin-right: 220px; 1338 1338 text-decoration:underline; 1339 1339 } 1340 1341 #pass-strength-result { 1342 padding: 3px 5px 3px 5px; 1343 margin-top: 3px; 1344 text-align: center; 1345 background-color: #e3e3e3; 1346 border: 1px solid #000000; 1347 } 1348 1349 #pass-strength-result.short { 1350 background-color: #e3e3e3; 1351 border: 1px solid #000000; 1352 } 1353 1354 #pass-strength-result.bad { 1355 background-color: #ffeff7; 1356 border: 1px solid #cc6699; 1357 } 1358 1359 #pass-strength-result.good { 1360 background-color: #effff4; 1361 border: 1px solid #66cc87; 1362 } 1363 1364 #pass-strength-result.strong { 1365 background-color: #59ef86; 1366 border: 1px solid #319f52; 1367 } 1368 1369 #pass-strength-iesucks { 1370 font-size: 8pt; 1371 text-align: center; 1372 } -
wp-includes/script-loader.php
old new 116 116 ) ); 117 117 $this->add( 'admin-categories', '/wp-admin/js/categories.js', array('listman'), '3684' ); 118 118 $this->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('listman'), '3733' ); 119 $this->add( 'password-strength-meter', '/wp-admin/js/passwordStrengthMeter.js', array('jquery'), '20070405' ); 120 $this->localize( 'password-strength-meter', 'pwsL10n', array( 121 'short' => __('Too short'), 122 'bad' => __('Bad'), 123 'good' => __('Good'), 124 'strong' => __('Strong') 125 ) ); 119 126 $this->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('listman'), '20070327' ); 120 127 $this->add( 'admin-users', '/wp-admin/js/users.js', array('listman'), '4583' ); 121 128 $this->add( 'xfn', '/wp-admin/js/xfn.js', false, '3517' );
