function checkPasswordComplexity(input) {
    if (input.length < 8) {
        return false;
    }

    if (!/[A-Z]/.test(input)) {
        return false;
    }

    if (!/[a-z]/.test(input)) {
        return false;
    }

    if (!/[0-9]/.test(input)) {
        return false;
    }

    if (!/[^a-zA-Z0-9]/.test(input)) {
        return false;
    }

    return true;
}
function check_pw_strenght() {
    var the = $("#password").val();
    var score = 0;
    
    if (checkLength(the) === true) {
        score = score + 20;
    }

    if (checkLowercase(the) === true) {
        score = score + 20;
    }

    if ( checkUppercase(the) === true ) {
        score = score + 20;
    }

    if (checkDigit(the) === true ) {
        score = score + 20;
    }

    if (checkChar(the) === true ) {
        score = score + 20;
    }

    $("#password_score").val(score);
    highlight(score);
}

function checkLength(the) {
    return the.length >= 8;  // 20 score
}

function checkLowercase(the) {
    return /[a-z]/.test(the);  // 20 score
}

function checkUppercase(the) {
    return /[A-Z]/.test(the);  // 20 score
}

function checkDigit(the) {
    return /[0-9]/.test(the);  // 20 score
}
function checkChar(the) {
    return /[^a-zA-Z0-9]/.test(the);  // 20 score
}    
function highlight(score) {
    var color = 'danger';
    var display = 'block';
    var text = 'This password has a strength of <b class="pw_score">'+score+'%</b>, but the system requires at least 80%.';
    if ( score >= 60 ) {
        color = 'warning';
    } 
    if ( score >= 80 ) {
        color = 'info';
        text = 'Password strength is good <b class="">'+score+'%</b>.';
    } 
    if ( score >= 100 ) {
        color = 'success';
        text = 'Password strength is great <b class="">'+score+'%</b>.';
    } 
    $(".pw_score_div").removeClass('text-danger text-warning text-info text-success');
    $(".pw_score_div").addClass('text-'+color);
    $(".pw_score_div").html(text);
}

function toggle_password(x){
    var ele = $(x).attr('data-for');
    if($('#'+ele).prop("type") == 'password' ){
        $('#'+ele).prop("type",'text')
        $(x).children('.fa-eye-slash').addClass('d-none');
        $(x).children('.fa-eye').removeClass('d-none');
    }else{
        $('#'+ele).prop("type",'password')
        $(x).children('.fa-eye-slash').removeClass('d-none');
        $(x).children('.fa-eye').addClass('d-none');
    }
}
$(".pw-icon").click(function(e) {
    toggle_password(this);
    e.preventDefault();
});
$("#password").keyup(function(e) {
    check_pw_strenght();
    e.preventDefault();
});