Changeset 8722

Show
Ignore:
Timestamp:
08/24/08 14:35:46 (3 months ago)
Author:
azaozz
Message:

Few small improvements to the password strength meter.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/js/password-strength-meter.js

    r7302 r8722  
    44// for more information : http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/ 
    55 
    6 var shortPass = pwsL10n.short 
    7 var badPass = pwsL10n.bad 
    8 var goodPass = pwsL10n.good 
    9 var strongPass = pwsL10n.strong 
    10  
    11  
    126function passwordStrength(password,username) { 
    13     score = 0 
     7    var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4, score = 0, d, s, u, l; 
    148 
    159    //password < 4 
    16     if (password.length < 4 ) { return shortPass } 
     10    if (password.length < 4 ) { return shortPass }; 
    1711 
    1812    //password == username 
    19     if (password.toLowerCase()==username.toLowerCase()) return badPass 
     13    if (password.toLowerCase()==username.toLowerCase()) return badPass; 
    2014 
    2115    //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; 
    2721 
    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; 
    3029 
    3130    //password has 2 sybols 
    32     if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5 
     31    if ( s && s.length > 1 ) score += 10; 
    3332 
    3433    //password has Upper and Lower chars 
    35     if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  score += 10 
     34    if ( u && l ) score += 10; 
    3635 
    3736    //password has number and chars 
    38     if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))  score += 15 
     37    if ( u && l && d ) score += 15; 
    3938    // 
    4039    //password has number and symbol 
    41     if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/))  score += 15 
     40    if ( s && d ) score += 15; 
    4241 
    43     //password has char and symbol 
    44     if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/))  score += 15 
     42    //password has Upper char and symbol 
     43    if ( u && s ) score += 15; 
    4544 
    4645    //password is just a nubers or chars 
    47     if (password.match(/^\w+$/) || password.match(/^\d+$/) )  score -= 10 
     46    if ( ! s )  score -= 10; 
    4847 
    4948    //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; 
    5251 
    53     if (score < 34 )  return badPass 
    54     if (score < 68 )  return goodPass 
    55     return strongPass 
     52    if ( score < 34 ) return badPass; 
     53    if ( score < 68 || password.length < 7 ) return goodPass; 
     54    return strongPass; 
    5655} 
    5756 
  • trunk/wp-admin/user-edit.php

    r8701 r8722  
    2424?> 
    2525<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        } 
    3338 
    3439        var strength = passwordStrength(pass, user); 
    3540 
    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(); 
    4160        } 
    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 ); 
    7269        $('.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); 
    7870    }); 
     71})(jQuery); 
    7972</script> 
    8073<?php 
     
    350343        <?php if ( $is_profile_page ): ?> 
    351344        <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 !"?$%^&amp;( 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 ! " ? $ % ^ &amp; ).'); ?></p> 
    353347        <?php endif; ?> 
    354348    </td> 
  • trunk/wp-includes/script-loader.php

    r8720 r8722  
    117117        $scripts->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists'), '20071031' ); 
    118118        $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'), '20070405' ); 
     119        $scripts->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20080824' ); 
    120120        $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'), 
    124125            'strong' => __('Strong') 
    125126        ) );