WordPress.org

Make WordPress Core

Ticket #6226: password-strength-i18n.diff

File password-strength-i18n.diff, 4.1 KB (added by nbachiyski, 10 years ago)

I18n for password strength meter, also its code was repeated twice in the js file!

  • wp-admin/js/password-strength-meter.js

     
    33// Firas Kassem  phiras.wordpress.com || phiras at gmail {dot} com
    44// for more information : http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/
    55
    6 var shortPass = 'Too short'
    7 var badPass = 'Bad'
    8 var goodPass = 'Good'
    9 var strongPass = 'Strong'
     6var shortPass = pwsL10n.short
     7var badPass = pwsL10n.bad
     8var goodPass = pwsL10n.good
     9var strongPass = pwsL10n.strong
    1010
    1111
    12 
    13 function passwordStrength(password,username)
    14 {
     12function passwordStrength(password,username) {
    1513    score = 0
    1614
    1715    //password < 4
     
    7977    }
    8078    return res
    8179}
    82 // Password strength meter
    83 // This jQuery plugin is written by firas kassem [2007.04.05]
    84 // Firas Kassem  phiras.wordpress.com || phiras at gmail {dot} com
    85 // for more information : http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/
    8680
    87 var shortPass = 'Too short'
    88 var badPass = 'Bad'
    89 var goodPass = 'Good'
    90 var strongPass = 'Strong'
    91 
    92 
    93 
    94 function passwordStrength(password,username)
    95 {
    96     score = 0
    97 
    98     //password < 4
    99     if (password.length < 4 ) { return shortPass }
    100 
    101     //password == username
    102     if (password.toLowerCase()==username.toLowerCase()) return badPass
    103 
    104     //password length
    105     score += password.length * 4
    106     score += ( checkRepetition(1,password).length - password.length ) * 1
    107     score += ( checkRepetition(2,password).length - password.length ) * 1
    108     score += ( checkRepetition(3,password).length - password.length ) * 1
    109     score += ( checkRepetition(4,password).length - password.length ) * 1
    110 
    111     //password has 3 numbers
    112     if (password.match(/(.*[0-9].*[0-9].*[0-9])/))  score += 5
    113 
    114     //password has 2 sybols
    115     if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5
    116 
    117     //password has Upper and Lower chars
    118     if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  score += 10
    119 
    120     //password has number and chars
    121     if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))  score += 15
    122     //
    123     //password has number and symbol
    124     if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/))  score += 15
    125 
    126     //password has char and symbol
    127     if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/))  score += 15
    128 
    129     //password is just a nubers or chars
    130     if (password.match(/^\w+$/) || password.match(/^\d+$/) )  score -= 10
    131 
    132     //verifing 0 < score < 100
    133     if ( score < 0 )  score = 0
    134     if ( score > 100 )  score = 100
    135 
    136     if (score < 34 )  return badPass
    137     if (score < 68 )  return goodPass
    138     return strongPass
    139 }
    140 
    141 
    142 // checkRepetition(1,'aaaaaaabcbc')   = 'abcbc'
    143 // checkRepetition(2,'aaaaaaabcbc')   = 'aabc'
    144 // checkRepetition(2,'aaaaaaabcdbcd') = 'aabcd'
    145 
    146 function checkRepetition(pLen,str) {
    147     res = ""
    148     for ( i=0; i<str.length ; i++ ) {
    149         repeated=true
    150         for (j=0;j < pLen && (j+i+pLen) < str.length;j++)
    151             repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen))
    152         if (j<pLen) repeated=false
    153         if (repeated) {
    154             i+=pLen-1
    155             repeated=false
    156         }
    157         else {
    158             res+=str.charAt(i)
    159         }
    160     }
    161     return res
    162 }
  • wp-admin/user-edit.php

     
    2222
    2323                jQuery(res).removeClass('short bad good strong');
    2424
    25                 if ( strength == 'Bad' ) {
     25                if ( strength == pwsL10n.bad ) {
    2626                        jQuery(res).addClass('bad');
    2727                        jQuery(res).html( pwsL10n.bad );
    2828                }
    29                 else if ( strength == 'Good' ) {
     29                else if ( strength == pwsL10n.good ) {
    3030                        jQuery(res).addClass('good');
    3131                        jQuery(res).html( pwsL10n.good );
    3232                }
    33                 else if ( strength == 'Strong' ) {
     33                else if ( strength == pwsL10n.strong ) {
    3434                        jQuery(res).addClass('strong');
    3535                        jQuery(res).html( pwsL10n.strong );
    3636                }