I’m using a little script to check the password strength in an inscription form, here is a relevant part of the script:
$('#password').keyup(function(){
var password = $(this).val();
password = $.trim(password);
var lettre_min = /[a-z]/;
var lettre_maj =/[A-Z]/;
var nombre = /[0-9]/;
var symbole = /[\`\!\"\?\$\%\^\&\*\(\)\_\-\+\=\{\[\}\]\:\;\@\'\~\#\|\\\<\,\>\.\/]/;
if(password.length != 0)
{
//password moin de 8 caractères
if(password.length <8)
{
$('.bar').animate({width:'50px',height:'5px'},200).show();
$('.bar').css('background-color','red');
$('.error').text('Too short').show();
}else
//password faible
if((password.match(lettre_min)) && password.length <12)
{
$('.bar').animate({width:'75px',height:'5px'},200).show();
$('.bar').css('background-color','red');
$('.error').text('Weak').show();
}else
//password moyen
//1 type
if((password.match(lettre_min)) && (password.match(nombre)) && password.length <12)
{
$('.bar').animate({width:'100px',height:'5px'},200).show();
$('.bar').css('background-color','orange');
$('.error').text('Average').show();
}else ...
The problem is: if I put letters (lettre_min) AND numbers (nombre) on the form input, he tells me the password is weak when he should tell me that it is average. He totally ignores the second condition.
I have no clue what’s going on =/
PS: I’m sorry if there is already an answer for this in an other question but I don’t even know what the problem is, so I don’t know what to search for =/
A Quick solution:
If
if((password.match(lettre_min)) && (password.match(nombre)) && password.length <12)is true thanif((password.match(lettre_min)) && password.length <12)is true too.