iLexN
6/19/2013 - 1:47 AM

Test Password Strength

Test Password Strength

$('#pass').keyup(function(e) {
     var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\W).*$", "g");
     var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
     var enoughRegex = new RegExp("(?=.{6,}).*", "g");
     if (false == enoughRegex.test($(this).val())) {
             $('#passstrength').html('More Characters');
     } else if (strongRegex.test($(this).val())) {
             $('#passstrength').className = 'ok';
             $('#passstrength').html('Strong!');
     } else if (mediumRegex.test($(this).val())) {
             $('#passstrength').className = 'alert';
             $('#passstrength').html('Medium!');
     } else {
             $('#passstrength').className = 'error';
             $('#passstrength').html('Weak!');
     }
     return true;
});
http://timseverien.nl/passy/



var $input = $( '#input' );
var $output = $( '#output' );

$.passy.requirements.length.min = 4;

var feedback = [
    { color: '#c00', text: 'poor' },
    { color: '#c80', text: 'okay' },
    { color: '#0c0', text: 'good' },
    { color: '#0c0', text: 'fabolous!' }
];

$input.passy(function(strength, valid) {
        $output.text(feedback[strength].text);
        $output.css('background-color', feedback[strength].color);

        if( valid ) $input.css(' border-color', 'green' );
        else $input.css( 'border-color', 'red' );
    });

$('#generate').click(function() {
    $input.passy( 'generate', 8 );
});