2009-05-25 01:39:56 +02:00
|
|
|
(function($){
|
|
|
|
|
2010-10-12 22:29:19 +02: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-25 01:39:56 +02:00
|
|
|
function check_pass_strength() {
|
2010-03-31 10:45:51 +02:00
|
|
|
var pass1 = $('#pass1').val(), user = $('#user_login').val(), pass2 = $('#pass2').val(), strength;
|
2009-05-25 01:39:56 +02:00
|
|
|
|
|
|
|
$('#pass-strength-result').removeClass('short bad good strong');
|
2010-03-31 10:45:51 +02:00
|
|
|
if ( ! pass1 ) {
|
2009-05-25 01:39:56 +02:00
|
|
|
$('#pass-strength-result').html( pwsL10n.empty );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-31 10:45:51 +02:00
|
|
|
strength = passwordStrength(pass1, user, pass2);
|
2009-05-25 01:39:56 +02: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 10:45:51 +02:00
|
|
|
case 5:
|
|
|
|
$('#pass-strength-result').addClass('short').html( pwsL10n['mismatch'] );
|
|
|
|
break;
|
2009-05-25 01:39:56 +02:00
|
|
|
default:
|
|
|
|
$('#pass-strength-result').addClass('short').html( pwsL10n['short'] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready( function() {
|
|
|
|
$('#pass1').val('').keyup( check_pass_strength );
|
2010-03-31 10:45:51 +02:00
|
|
|
$('#pass2').val('').keyup( check_pass_strength );
|
2010-09-25 12:58:01 +02:00
|
|
|
$('#pass-strength-result').show();
|
2009-05-25 01:39:56 +02: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 23:34:43 +01: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-25 01:39:56 +02:00
|
|
|
});
|
|
|
|
$('#first_name, #last_name').blur(function(){
|
2010-03-01 23:34:43 +01:00
|
|
|
var select = $('#display_name');
|
2009-05-25 01:39:56 +02:00
|
|
|
var first = $('#first_name').val(), last = $('#last_name').val();
|
2010-03-01 23:34:43 +01:00
|
|
|
var sel = select.children('option:selected').attr('id');
|
2009-05-25 01:39:56 +02:00
|
|
|
$('#display_firstname, #display_lastname, #display_firstlast, #display_lastfirst').remove();
|
2010-03-01 23:34:43 +01: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-25 01:39:56 +02:00
|
|
|
if ( first && last ) {
|
2010-03-01 23:34:43 +01: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-25 01:39:56 +02:00
|
|
|
}
|
2010-03-01 23:34:43 +01:00
|
|
|
$('#'+sel).attr('selected', 'selected');
|
2009-05-25 01:39:56 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery);
|