Add Password Mismatch feedback to the Password Strength Meter. Props dancole. Fixes #12576
git-svn-id: http://svn.automattic.com/wordpress/trunk@13900 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5f50e18c0b
commit
db0706ea0e
|
@ -249,7 +249,8 @@ var pwsL10n = {
|
||||||
short: "<?php echo esc_js( __( 'Very weak' ) ); ?>",
|
short: "<?php echo esc_js( __( 'Very weak' ) ); ?>",
|
||||||
bad: "<?php echo esc_js( __( 'Weak' ) ); ?>",
|
bad: "<?php echo esc_js( __( 'Weak' ) ); ?>",
|
||||||
good: "<?php echo esc_js( __( 'Medium' ) ); ?>",
|
good: "<?php echo esc_js( __( 'Medium' ) ); ?>",
|
||||||
strong: "<?php echo esc_js( __( 'Strong' ) ); ?>"
|
strong: "<?php echo esc_js( __( 'Strong' ) ); ?>",
|
||||||
|
mismatch: "<?php echo esc_js( __( 'Mismatch' ) ); ?>"
|
||||||
};
|
};
|
||||||
try{convertEntities(pwsL10n);}catch(e){};
|
try{convertEntities(pwsL10n);}catch(e){};
|
||||||
/* ]]> */
|
/* ]]> */
|
||||||
|
|
|
@ -1,21 +1,36 @@
|
||||||
// Password strength meter
|
// Password strength meter
|
||||||
function passwordStrength(password,username) {
|
function passwordStrength(password1, username, password2) {
|
||||||
var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4, symbolSize = 0, natLog, score;
|
var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4, mismatch = 5, symbolSize = 0, natLog, score;
|
||||||
|
|
||||||
|
// password 1 != password 2
|
||||||
|
if ( (password1 != password2) && password2.length > 0)
|
||||||
|
return mismatch
|
||||||
|
|
||||||
//password < 4
|
//password < 4
|
||||||
if (password.length < 4 ) { return shortPass };
|
if ( password1.length < 4 )
|
||||||
|
return shortPass
|
||||||
|
|
||||||
//password == username
|
//password1 == username
|
||||||
if (password.toLowerCase()==username.toLowerCase()) return badPass;
|
if ( password1.toLowerCase() == username.toLowerCase() )
|
||||||
|
return badPass;
|
||||||
|
|
||||||
if (password.match(/[0-9]/)) symbolSize +=10;
|
if ( password1.match(/[0-9]/) )
|
||||||
if (password.match(/[a-z]/)) symbolSize +=26;
|
symbolSize +=10;
|
||||||
if (password.match(/[A-Z]/)) symbolSize +=26;
|
if ( password1.match(/[a-z]/) )
|
||||||
if (password.match(/[^a-zA-Z0-9]/)) symbolSize +=31;
|
symbolSize +=26;
|
||||||
|
if ( password1.match(/[A-Z]/) )
|
||||||
|
symbolSize +=26;
|
||||||
|
if ( password1.match(/[^a-zA-Z0-9]/) )
|
||||||
|
symbolSize +=31;
|
||||||
|
|
||||||
natLog = Math.log( Math.pow(symbolSize,password.length) );
|
natLog = Math.log( Math.pow(symbolSize, password1.length) );
|
||||||
score = natLog / Math.LN2;
|
score = natLog / Math.LN2;
|
||||||
if (score < 40 ) return badPass
|
|
||||||
if (score < 56 ) return goodPass
|
if (score < 40 )
|
||||||
|
return badPass
|
||||||
|
|
||||||
|
if (score < 56 )
|
||||||
|
return goodPass
|
||||||
|
|
||||||
return strongPass;
|
return strongPass;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
function passwordStrength(i,f){var h=1,e=2,b=3,a=4,d=0,g,c;if(i.length<4){return h}if(i.toLowerCase()==f.toLowerCase()){return e}if(i.match(/[0-9]/)){d+=10}if(i.match(/[a-z]/)){d+=26}if(i.match(/[A-Z]/)){d+=26}if(i.match(/[^a-zA-Z0-9]/)){d+=31}g=Math.log(Math.pow(d,i.length));c=g/Math.LN2;if(c<40){return e}if(c<56){return b}return a};
|
function passwordStrength(password1,username,password2){var shortPass=1,badPass=2,goodPass=3,strongPass=4,mismatch=5,symbolSize=0,natLog,score;if((password1!=password2)&&password2.length>0){return mismatch}if(password1.length<4){return shortPass}if(password1.toLowerCase()==username.toLowerCase()){return badPass}if(password1.match(/[0-9]/)){symbolSize+=10}if(password1.match(/[a-z]/)){symbolSize+=26}if(password1.match(/[A-Z]/)){symbolSize+=26}if(password1.match(/[^a-zA-Z0-9]/)){symbolSize+=31}natLog=Math.log(Math.pow(symbolSize,password1.length));score=natLog/Math.LN2;if(score<40){return badPass}if(score<56){return goodPass}return strongPass};
|
|
@ -1,15 +1,15 @@
|
||||||
(function($){
|
(function($){
|
||||||
|
|
||||||
function check_pass_strength() {
|
function check_pass_strength() {
|
||||||
var pass = $('#pass1').val(), user = $('#user_login').val(), strength;
|
var pass1 = $('#pass1').val(), user = $('#user_login').val(), pass2 = $('#pass2').val(), strength;
|
||||||
|
|
||||||
$('#pass-strength-result').removeClass('short bad good strong');
|
$('#pass-strength-result').removeClass('short bad good strong');
|
||||||
if ( ! pass ) {
|
if ( ! pass1 ) {
|
||||||
$('#pass-strength-result').html( pwsL10n.empty );
|
$('#pass-strength-result').html( pwsL10n.empty );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
strength = passwordStrength(pass, user);
|
strength = passwordStrength(pass1, user, pass2);
|
||||||
|
|
||||||
switch ( strength ) {
|
switch ( strength ) {
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -21,6 +21,9 @@
|
||||||
case 4:
|
case 4:
|
||||||
$('#pass-strength-result').addClass('strong').html( pwsL10n['strong'] );
|
$('#pass-strength-result').addClass('strong').html( pwsL10n['strong'] );
|
||||||
break;
|
break;
|
||||||
|
case 5:
|
||||||
|
$('#pass-strength-result').addClass('short').html( pwsL10n['mismatch'] );
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
$('#pass-strength-result').addClass('short').html( pwsL10n['short'] );
|
$('#pass-strength-result').addClass('short').html( pwsL10n['short'] );
|
||||||
}
|
}
|
||||||
|
@ -28,6 +31,7 @@
|
||||||
|
|
||||||
$(document).ready( function() {
|
$(document).ready( function() {
|
||||||
$('#pass1').val('').keyup( check_pass_strength );
|
$('#pass1').val('').keyup( check_pass_strength );
|
||||||
|
$('#pass2').val('').keyup( check_pass_strength );
|
||||||
$('.color-palette').click(function(){$(this).siblings('input[name=admin_color]').attr('checked', 'checked')});
|
$('.color-palette').click(function(){$(this).siblings('input[name=admin_color]').attr('checked', 'checked')});
|
||||||
$('#nickname').blur(function(){
|
$('#nickname').blur(function(){
|
||||||
var str = $(this).val() || $('#user_login').val();
|
var str = $(this).val() || $('#user_login').val();
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
(function(a){function b(){var d=a("#pass1").val(),c=a("#user_login").val(),e;a("#pass-strength-result").removeClass("short bad good strong");if(!d){a("#pass-strength-result").html(pwsL10n.empty);return}e=passwordStrength(d,c);switch(e){case 2:a("#pass-strength-result").addClass("bad").html(pwsL10n.bad);break;case 3:a("#pass-strength-result").addClass("good").html(pwsL10n.good);break;case 4:a("#pass-strength-result").addClass("strong").html(pwsL10n.strong);break;default:a("#pass-strength-result").addClass("short").html(pwsL10n["short"])}}a(document).ready(function(){a("#pass1").val("").keyup(b);a(".color-palette").click(function(){a(this).siblings("input[name=admin_color]").attr("checked","checked")});a("#nickname").blur(function(){var e=a(this).val()||a("#user_login").val();var c=a("#display_name");var d=c.children("option:selected").attr("id");c.children("#display_nickname").remove();if(!c.children("option[value="+e+"]").length){c.append('<option id="display_nickname" value="'+e+'">'+e+"</option>")}a("#"+d).attr("selected","selected")});a("#first_name, #last_name").blur(function(){var c=a("#display_name");var f=a("#first_name").val(),d=a("#last_name").val();var e=c.children("option:selected").attr("id");a("#display_firstname, #display_lastname, #display_firstlast, #display_lastfirst").remove();if(f&&!c.children("option[value="+f+"]").length){c.append('<option id="display_firstname" value="'+f+'">'+f+"</option>")}if(d&&!c.children("option[value="+d+"]").length){c.append('<option id="display_lastname" value="'+d+'">'+d+"</option>")}if(f&&d){if(!c.children("option[value="+f+" "+d+"]").length){c.append('<option id="display_firstlast" value="'+f+" "+d+'">'+f+" "+d+"</option>")}if(!c.children("option[value="+d+" "+f+"]").length){c.append('<option id="display_lastfirst" value="'+d+" "+f+'">'+d+" "+f+"</option>")}}a("#"+e).attr("selected","selected")})})})(jQuery);
|
(function($){function check_pass_strength(){var pass1=$("#pass1").val(),user=$("#user_login").val(),pass2=$("#pass2").val(),strength;$("#pass-strength-result").removeClass("short bad good strong");if(!pass1){$("#pass-strength-result").html(pwsL10n.empty);return}strength=passwordStrength(pass1,user,pass2);switch(strength){case 2:$("#pass-strength-result").addClass("bad").html(pwsL10n.bad);break;case 3:$("#pass-strength-result").addClass("good").html(pwsL10n.good);break;case 4:$("#pass-strength-result").addClass("strong").html(pwsL10n.strong);break;case 5:$("#pass-strength-result").addClass("short").html(pwsL10n.mismatch);break;default:$("#pass-strength-result").addClass("short").html(pwsL10n["short"])}}$(document).ready(function(){$("#pass1").val("").keyup(check_pass_strength);$("#pass2").val("").keyup(check_pass_strength);$(".color-palette").click(function(){$(this).siblings("input[name=admin_color]").attr("checked","checked")});$("#nickname").blur(function(){var str=$(this).val()||$("#user_login").val();var select=$("#display_name");var sel=select.children("option:selected").attr("id");select.children("#display_nickname").remove();if(!select.children("option[value="+str+"]").length){select.append('<option id="display_nickname" value="'+str+'">'+str+"</option>")}$("#"+sel).attr("selected","selected")});$("#first_name, #last_name").blur(function(){var select=$("#display_name");var first=$("#first_name").val(),last=$("#last_name").val();var sel=select.children("option:selected").attr("id");$("#display_firstname, #display_lastname, #display_firstlast, #display_lastfirst").remove();if(first&&!select.children("option[value="+first+"]").length){select.append('<option id="display_firstname" value="'+first+'">'+first+"</option>")}if(last&&!select.children("option[value="+last+"]").length){select.append('<option id="display_lastname" value="'+last+'">'+last+"</option>")}if(first&&last){if(!select.children("option[value="+first+" "+last+"]").length){select.append('<option id="display_firstlast" value="'+first+" "+last+'">'+first+" "+last+"</option>")}if(!select.children("option[value="+last+" "+first+"]").length){select.append('<option id="display_lastfirst" value="'+last+" "+first+'">'+last+" "+first+"</option>")}}$("#"+sel).attr("selected","selected")})})})(jQuery);
|
|
@ -251,7 +251,7 @@ function wp_default_scripts( &$scripts ) {
|
||||||
$scripts->add( 'admin-custom-fields', "/wp-admin/js/custom-fields$suffix.js", array('wp-lists'), '20090106' );
|
$scripts->add( 'admin-custom-fields', "/wp-admin/js/custom-fields$suffix.js", array('wp-lists'), '20090106' );
|
||||||
$scripts->add_data( 'admin-custom-fields', 'group', 1 );
|
$scripts->add_data( 'admin-custom-fields', 'group', 1 );
|
||||||
|
|
||||||
$scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array('jquery'), '20090102' );
|
$scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array('jquery'), '20100331' );
|
||||||
$scripts->add_data( 'password-strength-meter', 'group', 1 );
|
$scripts->add_data( 'password-strength-meter', 'group', 1 );
|
||||||
$scripts->localize( 'password-strength-meter', 'pwsL10n', array(
|
$scripts->localize( 'password-strength-meter', 'pwsL10n', array(
|
||||||
'empty' => __('Strength indicator'),
|
'empty' => __('Strength indicator'),
|
||||||
|
@ -260,6 +260,7 @@ function wp_default_scripts( &$scripts ) {
|
||||||
/* translators: password strength */
|
/* translators: password strength */
|
||||||
'good' => _x('Medium', 'password strength'),
|
'good' => _x('Medium', 'password strength'),
|
||||||
'strong' => __('Strong'),
|
'strong' => __('Strong'),
|
||||||
|
'mismatch' => __('Mismatch'),
|
||||||
'l10n_print_after' => 'try{convertEntities(pwsL10n);}catch(e){};'
|
'l10n_print_after' => 'try{convertEntities(pwsL10n);}catch(e){};'
|
||||||
) );
|
) );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue