2009-05-24 19:39:56 -04:00
|
|
|
(function($){
|
|
|
|
|
2010-10-12 16:29:19 -04:00
|
|
|
function passwordStrength(password1, username, password2) {
|
|
|
|
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
|
|
|
|
if ( password1.length < 4 )
|
|
|
|
return shortPass
|
|
|
|
|
|
|
|
//password1 == username
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-05-24 19:39:56 -04:00
|
|
|
function check_pass_strength() {
|
2010-03-31 04:45:51 -04:00
|
|
|
var pass1 = $('#pass1').val(), user = $('#user_login').val(), pass2 = $('#pass2').val(), strength;
|
2009-05-24 19:39:56 -04:00
|
|
|
|
|
|
|
$('#pass-strength-result').removeClass('short bad good strong');
|
2010-03-31 04:45:51 -04:00
|
|
|
if ( ! pass1 ) {
|
2009-05-24 19:39:56 -04:00
|
|
|
$('#pass-strength-result').html( pwsL10n.empty );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-31 04:45:51 -04:00
|
|
|
strength = passwordStrength(pass1, user, pass2);
|
2009-05-24 19:39:56 -04:00
|
|
|
|
|
|
|
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;
|
2010-03-31 04:45:51 -04:00
|
|
|
case 5:
|
|
|
|
$('#pass-strength-result').addClass('short').html( pwsL10n['mismatch'] );
|
|
|
|
break;
|
2009-05-24 19:39:56 -04:00
|
|
|
default:
|
|
|
|
$('#pass-strength-result').addClass('short').html( pwsL10n['short'] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready( function() {
|
|
|
|
$('#pass1').val('').keyup( check_pass_strength );
|
2010-03-31 04:45:51 -04:00
|
|
|
$('#pass2').val('').keyup( check_pass_strength );
|
2010-09-25 06:58:01 -04:00
|
|
|
$('#pass-strength-result').show();
|
2009-05-24 19:39:56 -04:00
|
|
|
$('.color-palette').click(function(){$(this).siblings('input[name=admin_color]').attr('checked', 'checked')});
|
|
|
|
$('#nickname').blur(function(){
|
|
|
|
var str = $(this).val() || $('#user_login').val();
|
2010-03-01 17:34:43 -05:00
|
|
|
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');
|
2009-05-24 19:39:56 -04:00
|
|
|
});
|
|
|
|
$('#first_name, #last_name').blur(function(){
|
2010-03-01 17:34:43 -05:00
|
|
|
var select = $('#display_name');
|
2009-05-24 19:39:56 -04:00
|
|
|
var first = $('#first_name').val(), last = $('#last_name').val();
|
2010-03-01 17:34:43 -05:00
|
|
|
var sel = select.children('option:selected').attr('id');
|
2009-05-24 19:39:56 -04:00
|
|
|
$('#display_firstname, #display_lastname, #display_firstlast, #display_lastfirst').remove();
|
2010-03-01 17:34:43 -05:00
|
|
|
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>');
|
2009-05-24 19:39:56 -04:00
|
|
|
if ( first && last ) {
|
2010-03-01 17:34:43 -05:00
|
|
|
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>');
|
2009-05-24 19:39:56 -04:00
|
|
|
}
|
2010-03-01 17:34:43 -05:00
|
|
|
$('#'+sel).attr('selected', 'selected');
|
2009-05-24 19:39:56 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|