mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 09:37:42 +01:00
Few small improvements to the password strength meter.
git-svn-id: http://svn.automattic.com/wordpress/trunk@8722 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
67ef4e1abc
commit
f2dd6dd861
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -23,59 +23,52 @@ else
|
||||
function profile_js ( ) {
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
function check_pass_strength ( ) {
|
||||
(function($){
|
||||
|
||||
function check_pass_strength () {
|
||||
|
||||
var pass = jQuery('#pass1').val();
|
||||
var user = jQuery('#user_login').val();
|
||||
var pass = $('#pass1').val();
|
||||
var user = $('#user_login').val();
|
||||
|
||||
// get the result as an object, i'm tired of typing it
|
||||
var res = jQuery('#pass-strength-result');
|
||||
$('#pass-strength-result').removeClass('short bad good strong');
|
||||
if ( ! pass ) {
|
||||
$('#pass-strength-result').html( pwsL10n.empty );
|
||||
return;
|
||||
}
|
||||
|
||||
var strength = passwordStrength(pass, user);
|
||||
|
||||
jQuery(res).removeClass('short bad good strong');
|
||||
|
||||
if ( strength == pwsL10n.bad ) {
|
||||
jQuery(res).addClass('bad');
|
||||
jQuery(res).html( pwsL10n.bad );
|
||||
}
|
||||
else if ( strength == pwsL10n.good ) {
|
||||
jQuery(res).addClass('good');
|
||||
jQuery(res).html( pwsL10n.good );
|
||||
}
|
||||
else if ( strength == pwsL10n.strong ) {
|
||||
jQuery(res).addClass('strong');
|
||||
jQuery(res).html( pwsL10n.strong );
|
||||
}
|
||||
else {
|
||||
if ( 2 == strength )
|
||||
$('#pass-strength-result').addClass('bad').html( pwsL10n.bad );
|
||||
else if ( 3 == strength )
|
||||
$('#pass-strength-result').addClass('good').html( pwsL10n.good );
|
||||
else if ( 4 == strength )
|
||||
$('#pass-strength-result').addClass('strong').html( pwsL10n.strong );
|
||||
else
|
||||
// this catches 'Too short' and the off chance anything else comes along
|
||||
jQuery(res).addClass('short');
|
||||
jQuery(res).html( pwsL10n.short );
|
||||
}
|
||||
$('#pass-strength-result').addClass('short').html( pwsL10n.short );
|
||||
|
||||
}
|
||||
|
||||
function update_nickname ( ) {
|
||||
function update_nickname () {
|
||||
|
||||
var nickname = jQuery('#nickname').val();
|
||||
var display_nickname = jQuery('#display_nickname').val();
|
||||
var nickname = $('#nickname').val();
|
||||
var display_nickname = $('#display_nickname').val();
|
||||
|
||||
if ( nickname == '' ) {
|
||||
jQuery('#display_nickname').remove();
|
||||
$('#display_nickname').remove();
|
||||
}
|
||||
jQuery('#display_nickname').val(nickname).html(nickname);
|
||||
$('#display_nickname').val(nickname).html(nickname);
|
||||
|
||||
}
|
||||
|
||||
jQuery(function($) {
|
||||
$('#pass1').keyup( check_pass_strength )
|
||||
$(document).ready( function() {
|
||||
$('#pass1,#pass2').attr('autocomplete','off');
|
||||
$('#nickname').blur(update_nickname);
|
||||
$('#pass1').keyup( check_pass_strength );
|
||||
$('.color-palette').click(function(){$(this).siblings('input[name=admin_color]').attr('checked', 'checked')});
|
||||
} );
|
||||
|
||||
jQuery(document).ready( function() {
|
||||
jQuery('#pass1,#pass2').attr('autocomplete','off');
|
||||
jQuery('#nickname').blur(update_nickname);
|
||||
});
|
||||
})(jQuery);
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
@ -349,7 +342,8 @@ if ( $show_password_fields ) :
|
||||
<input type="password" name="pass2" id="pass2" size="16" value="" /> <?php _e("Type your new password again."); ?><br />
|
||||
<?php if ( $is_profile_page ): ?>
|
||||
<p><strong><?php _e('Password Strength'); ?></strong></p>
|
||||
<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.'); ?>
|
||||
<div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
|
||||
<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>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
@ -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' );
|
||||
|
Loading…
Reference in New Issue
Block a user