WordPress.org

Make WordPress Core

Changeset 9276


Ignore:
Timestamp:
10/22/2008 04:20:50 AM (10 years ago)
Author:
ryan
Message:

Improved password strength meter from Otto42. fixes #7124

Location:
trunk
Files:
2 edited

Legend:

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

    r8722 r9276  
    11// 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/
    52
    63function passwordStrength(password,username) {
    7     var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4, score = 0, d, s, u, l;
     4    var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4;
    85
    9     //password < 4
     6    //password < 4
    107    if (password.length < 4 ) { return shortPass };
    118
     
    1310    if (password.toLowerCase()==username.toLowerCase()) return badPass;
    1411
    15     //password length
    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;
    21 
    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;
    29 
    30     //password has 2 sybols
    31     if ( s && s.length > 1 ) score += 10;
    32 
    33     //password has Upper and Lower chars
    34     if ( u && l ) score += 10;
    35 
    36     //password has number and chars
    37     if ( u && l && d ) score += 15;
    38     //
    39     //password has number and symbol
    40     if ( s && d ) score += 15;
    41 
    42     //password has Upper char and symbol
    43     if ( u && s ) score += 15;
    44 
    45     //password is just a nubers or chars
    46     if ( ! s )  score -= 10;
    47 
    48     //verifing 0 < score < 100
    49     if ( score < 0 )  score = 0;
    50     if ( score > 100 )  score = 100;
    51 
    52     if ( score < 34 ) return badPass;
    53     if ( score < 68 || password.length < 7 ) return goodPass;
     12    var symbolSize = 0;
     13    if (password.match(/[0-9]/)) symbolSize +=10;
     14    if (password.match(/[a-z]/)) symbolSize +=26;
     15    if (password.match(/[A-Z]/)) symbolSize +=26;
     16    if (password.match(/[^a-zA-Z0-9]/)) symbolSize +=31;
     17   
     18    var natLog = Math.log( Math.pow(symbolSize,password.length) );
     19    var score = natLog / Math.LN2;
     20    if (score < 40 )  return badPass
     21    if (score < 56 )  return goodPass
    5422    return strongPass;
    5523}
    56 
    57 
    58 // checkRepetition(1,'aaaaaaabcbc')   = 'abcbc'
    59 // checkRepetition(2,'aaaaaaabcbc')   = 'aabc'
    60 // checkRepetition(2,'aaaaaaabcdbcd') = 'aabcd'
    61 
    62 function checkRepetition(pLen,str) {
    63     res = ""
    64     for ( i=0; i<str.length ; i++ ) {
    65         repeated=true
    66         for (j=0;j < pLen && (j+i+pLen) < str.length;j++)
    67             repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen))
    68         if (j<pLen) repeated=false
    69         if (repeated) {
    70             i+=pLen-1
    71             repeated=false
    72         }
    73         else {
    74             res+=str.charAt(i)
    75         }
    76     }
    77     return res
    78 }
    79 
  • trunk/wp-includes/script-loader.php

    r9243 r9276  
    148148        $scripts->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists', 'columns', 'settings-box'), '20080925' );
    149149        $scripts->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' );
    150         $scripts->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20080824' );
     150        $scripts->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20081021' );
    151151        $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
    152152            'empty' => __('Strength indicator'),
Note: See TracChangeset for help on using the changeset viewer.