Changeset 8722
- Timestamp:
- 08/24/2008 02:35:46 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/js/password-strength-meter.js
r7302 r8722 4 4 // for more information : http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/ 5 5 6 var shortPass = pwsL10n.short7 var badPass = pwsL10n.bad8 var goodPass = pwsL10n.good9 var strongPass = pwsL10n.strong10 11 12 6 function passwordStrength(password,username) { 13 score = 07 var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4, score = 0, d, s, u, l; 14 8 15 9 //password < 4 16 if (password.length < 4 ) { return shortPass } 10 if (password.length < 4 ) { return shortPass }; 17 11 18 12 //password == username 19 if (password.toLowerCase()==username.toLowerCase()) return badPass 13 if (password.toLowerCase()==username.toLowerCase()) return badPass; 20 14 21 15 //password length 22 score += password.length * 4 23 score += ( checkRepetition(1,password).length - password.length ) * 1 24 score += ( checkRepetition(2,password).length - password.length ) * 1 25 score += ( checkRepetition(3,password).length - password.length ) * 1 26 score += ( checkRepetition(4,password).length - password.length ) * 1 16 score += password.length * 4; 17 score += ( checkRepetition(1,password).length - password.length ) * 1; 18 score += ( checkRepetition(2,password).length - password.length ) * 1; 19 score += ( checkRepetition(3,password).length - password.length ) * 1; 20 score += ( checkRepetition(4,password).length - password.length ) * 1; 27 21 28 //password has 3 numbers 29 if (password.match(/(.*[0-9].*[0-9].*[0-9])/)) score += 5 22 d = password.match(/\d/g); 23 s = password.match(/[^\d\w]/g); 24 u = password.match(/[A-Z]/g); 25 l = password.match(/[a-z]/g); 26 27 //password has 3 numbers 28 if ( d && d.length > 2 ) score += 5; 30 29 31 30 //password has 2 sybols 32 if ( password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 531 if ( s && s.length > 1 ) score += 10; 33 32 34 33 //password has Upper and Lower chars 35 if ( password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) score += 1034 if ( u && l ) score += 10; 36 35 37 36 //password has number and chars 38 if ( password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) score += 1537 if ( u && l && d ) score += 15; 39 38 // 40 39 //password has number and symbol 41 if ( password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/)) score += 1540 if ( s && d ) score += 15; 42 41 43 //password has char and symbol44 if ( password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/)) score += 1542 //password has Upper char and symbol 43 if ( u && s ) score += 15; 45 44 46 45 //password is just a nubers or chars 47 if ( password.match(/^\w+$/) || password.match(/^\d+$/) ) score -= 1046 if ( ! s ) score -= 10; 48 47 49 48 //verifing 0 < score < 100 50 if ( score < 0 ) score = 0 51 if ( score > 100 ) score = 100 49 if ( score < 0 ) score = 0; 50 if ( score > 100 ) score = 100; 52 51 53 if ( score < 34 ) return badPass54 if ( score < 68 ) return goodPass55 return strongPass 52 if ( score < 34 ) return badPass; 53 if ( score < 68 || password.length < 7 ) return goodPass; 54 return strongPass; 56 55 } 57 56 -
trunk/wp-admin/user-edit.php
r8701 r8722 24 24 ?> 25 25 <script type="text/javascript"> 26 function check_pass_strength ( ) { 27 28 var pass = jQuery('#pass1').val(); 29 var user = jQuery('#user_login').val(); 30 31 // get the result as an object, i'm tired of typing it 32 var res = jQuery('#pass-strength-result'); 26 (function($){ 27 28 function check_pass_strength () { 29 30 var pass = $('#pass1').val(); 31 var user = $('#user_login').val(); 32 33 $('#pass-strength-result').removeClass('short bad good strong'); 34 if ( ! pass ) { 35 $('#pass-strength-result').html( pwsL10n.empty ); 36 return; 37 } 33 38 34 39 var strength = passwordStrength(pass, user); 35 40 36 jQuery(res).removeClass('short bad good strong'); 37 38 if ( strength == pwsL10n.bad ) { 39 jQuery(res).addClass('bad'); 40 jQuery(res).html( pwsL10n.bad ); 41 if ( 2 == strength ) 42 $('#pass-strength-result').addClass('bad').html( pwsL10n.bad ); 43 else if ( 3 == strength ) 44 $('#pass-strength-result').addClass('good').html( pwsL10n.good ); 45 else if ( 4 == strength ) 46 $('#pass-strength-result').addClass('strong').html( pwsL10n.strong ); 47 else 48 // this catches 'Too short' and the off chance anything else comes along 49 $('#pass-strength-result').addClass('short').html( pwsL10n.short ); 50 51 } 52 53 function update_nickname () { 54 55 var nickname = $('#nickname').val(); 56 var display_nickname = $('#display_nickname').val(); 57 58 if ( nickname == '' ) { 59 $('#display_nickname').remove(); 41 60 } 42 else if ( strength == pwsL10n.good ) { 43 jQuery(res).addClass('good'); 44 jQuery(res).html( pwsL10n.good ); 45 } 46 else if ( strength == pwsL10n.strong ) { 47 jQuery(res).addClass('strong'); 48 jQuery(res).html( pwsL10n.strong ); 49 } 50 else { 51 // this catches 'Too short' and the off chance anything else comes along 52 jQuery(res).addClass('short'); 53 jQuery(res).html( pwsL10n.short ); 54 } 55 56 } 57 58 function update_nickname ( ) { 59 60 var nickname = jQuery('#nickname').val(); 61 var display_nickname = jQuery('#display_nickname').val(); 62 63 if ( nickname == '' ) { 64 jQuery('#display_nickname').remove(); 65 } 66 jQuery('#display_nickname').val(nickname).html(nickname); 67 68 } 69 70 jQuery(function($) { 71 $('#pass1').keyup( check_pass_strength ) 61 $('#display_nickname').val(nickname).html(nickname); 62 63 } 64 65 $(document).ready( function() { 66 $('#pass1,#pass2').attr('autocomplete','off'); 67 $('#nickname').blur(update_nickname); 68 $('#pass1').keyup( check_pass_strength ); 72 69 $('.color-palette').click(function(){$(this).siblings('input[name=admin_color]').attr('checked', 'checked')}); 73 } );74 75 jQuery(document).ready( function() {76 jQuery('#pass1,#pass2').attr('autocomplete','off');77 jQuery('#nickname').blur(update_nickname);78 70 }); 71 })(jQuery); 79 72 </script> 80 73 <?php … … 350 343 <?php if ( $is_profile_page ): ?> 351 344 <p><strong><?php _e('Password Strength'); ?></strong></p> 352 <div id="pass-strength-result"><?php _e('Too short'); ?></div> <?php _e('Hint: Use upper and lower case characters, numbers and symbols like !"?$%^&( in your password.'); ?> 345 <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div> 346 <p><?php _e('Hint: Your password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ & ).'); ?></p> 353 347 <?php endif; ?> 354 348 </td> -
trunk/wp-includes/script-loader.php
r8720 r8722 117 117 $scripts->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists'), '20071031' ); 118 118 $scripts->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' ); 119 $scripts->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '200 70405' );119 $scripts->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20080824' ); 120 120 $scripts->localize( 'password-strength-meter', 'pwsL10n', array( 121 'short' => __('Too short'), 122 'bad' => __('Bad'), 123 'good' => __('Good'), 121 'empty' => __('Strength indicator'), 122 'short' => __('Very weak'), 123 'bad' => __('Weak'), 124 'good' => __('Medium'), 124 125 'strong' => __('Strong') 125 126 ) );
Note: See TracChangeset
for help on using the changeset viewer.