From f2dd6dd861b4bb9ff3482c1cd6e8b197471d3e76 Mon Sep 17 00:00:00 2001 From: azaozz Date: Sun, 24 Aug 2008 14:35:46 +0000 Subject: [PATCH] Few small improvements to the password strength meter. git-svn-id: http://svn.automattic.com/wordpress/trunk@8722 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/password-strength-meter.js | 55 +++++++++++---------- wp-admin/user-edit.php | 66 ++++++++++++-------------- wp-includes/script-loader.php | 9 ++-- 3 files changed, 62 insertions(+), 68 deletions(-) diff --git a/wp-admin/js/password-strength-meter.js b/wp-admin/js/password-strength-meter.js index e90c3e04a4..f9f1d5341e 100644 --- a/wp-admin/js/password-strength-meter.js +++ b/wp-admin/js/password-strength-meter.js @@ -3,56 +3,55 @@ // Firas Kassem phiras.wordpress.com || phiras at gmail {dot} com // for more information : http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/ -var shortPass = pwsL10n.short -var badPass = pwsL10n.bad -var goodPass = pwsL10n.good -var strongPass = pwsL10n.strong - - function passwordStrength(password,username) { - score = 0 + var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4, score = 0, d, s, u, l; //password < 4 - if (password.length < 4 ) { return shortPass } + if (password.length < 4 ) { return shortPass }; //password == username - if (password.toLowerCase()==username.toLowerCase()) return badPass + if (password.toLowerCase()==username.toLowerCase()) return badPass; //password length - score += password.length * 4 - score += ( checkRepetition(1,password).length - password.length ) * 1 - score += ( checkRepetition(2,password).length - password.length ) * 1 - score += ( checkRepetition(3,password).length - password.length ) * 1 - score += ( checkRepetition(4,password).length - password.length ) * 1 + score += password.length * 4; + score += ( checkRepetition(1,password).length - password.length ) * 1; + score += ( checkRepetition(2,password).length - password.length ) * 1; + score += ( checkRepetition(3,password).length - password.length ) * 1; + score += ( checkRepetition(4,password).length - password.length ) * 1; - //password has 3 numbers - if (password.match(/(.*[0-9].*[0-9].*[0-9])/)) score += 5 + d = password.match(/\d/g); + s = password.match(/[^\d\w]/g); + u = password.match(/[A-Z]/g); + l = password.match(/[a-z]/g); + + //password has 3 numbers + if ( d && d.length > 2 ) score += 5; //password has 2 sybols - if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5 + if ( s && s.length > 1 ) score += 10; //password has Upper and Lower chars - if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) score += 10 + if ( u && l ) score += 10; //password has number and chars - if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) score += 15 + if ( u && l && d ) score += 15; // //password has number and symbol - if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/)) score += 15 + if ( s && d ) score += 15; - //password has char and symbol - if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/)) score += 15 + //password has Upper char and symbol + if ( u && s ) score += 15; //password is just a nubers or chars - if (password.match(/^\w+$/) || password.match(/^\d+$/) ) score -= 10 + if ( ! s ) score -= 10; //verifing 0 < score < 100 - if ( score < 0 ) score = 0 - if ( score > 100 ) score = 100 + if ( score < 0 ) score = 0; + if ( score > 100 ) score = 100; - if (score < 34 ) return badPass - if (score < 68 ) return goodPass - return strongPass + if ( score < 34 ) return badPass; + if ( score < 68 || password.length < 7 ) return goodPass; + return strongPass; } diff --git a/wp-admin/user-edit.php b/wp-admin/user-edit.php index e11d420a1b..cbc14234cd 100644 --- a/wp-admin/user-edit.php +++ b/wp-admin/user-edit.php @@ -23,59 +23,52 @@ else function profile_js ( ) { ?>

-
+
+

diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index a4da5e7009..042e54e37d 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -116,11 +116,12 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'admin-categories', '/wp-admin/js/categories.js', array('wp-lists'), '20071031' ); $scripts->add( 'admin-tags', '/wp-admin/js/tags.js', array('wp-lists'), '20071031' ); $scripts->add( 'admin-custom-fields', '/wp-admin/js/custom-fields.js', array('wp-lists'), '20070823' ); - $scripts->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20070405' ); + $scripts->add( 'password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20080824' ); $scripts->localize( 'password-strength-meter', 'pwsL10n', array( - 'short' => __('Too short'), - 'bad' => __('Bad'), - 'good' => __('Good'), + 'empty' => __('Strength indicator'), + 'short' => __('Very weak'), + 'bad' => __('Weak'), + 'good' => __('Medium'), 'strong' => __('Strong') ) ); $scripts->add( 'admin-comments', '/wp-admin/js/edit-comments.js', array('wp-lists', 'jquery-ui-draggable', 'jquery-ui-resizable'), '20080821' );