﻿function checkforce(){
    score=0;
    mot=document.getElementById('password_inscription').value;
    if(mot.length<8){
        document.getElementById('force').innerHTML="trop court";
    }
    else{
        if(mot.length>=12){
            score+=2;   
        }
        else if(mot.length>=10){
            score+=1; 
        }
        //1 que des chiffres
        var reg=new RegExp("^([0-9]*)$","g");
        if(mot.match(reg)){
            score+=1;
        }
        else{
            //2 uniquement des majuscules
            reg=new RegExp("(^[A-Z]*)$","g");
            if(mot.match(reg)){
                score+=2;
            }
            else{
                //3 uniquement des minuscles
                reg=new RegExp("(^[a-z]*)$","g");
                if(mot.match(reg)){
                    score+=2;
                }
                else{
                    //pas de caractère non alphanum
                    reg=new RegExp("^([a-zA-Z0-9]*)$","g");
                    if(mot.match(reg)){
                        score+=3;
                    } 
                    else{
                        score+=4;
                    }   
                }
            }
        }
        switch(score){
            case 0:
                document.getElementById('force').innerHTML="Trop court";    
                break;
            case 1:
                document.getElementById('force').innerHTML="<div align='left' style='border:1px solid #999999;background-color:#EEEEEE;width:160px;'><div style='width:40px;background-color:#CC0000;height:6px;font-size:4px'>&nbsp;</div></div>Faible";
                break;
            case 2:
                document.getElementById('force').innerHTML="<div align='left' style='border:1px solid #999999;background-color:#EEEEEE;width:160px;'><div style='width:80px;background-color:#FF8800;height:6px;font-size:4px'>&nbsp;</div></div>Moyen";
                 break;
            case 3:
                document.getElementById('force').innerHTML="<div align='left' style='border:1px solid #999999;background-color:#EEEEEE;width:160px;'><div style='width:120px;background-color:#0000CC;height:6px;font-size:4px'>&nbsp;</div></div>Fort";
                 break;
            case 4:
                document.getElementById('force').innerHTML="<div align='left' style='border:1px solid #999999;background-color:#EEEEEE;width:160px;'><div style='width:160px;background-color:#00DD00;height:6px;font-size:4px'>&nbsp;</div></div>Excellent";
                 break;
            default:
                document.getElementById('force').innerHTML="<div align='left' style='border:1px solid #999999;background-color:#EEEEEE;width:160px;'><div style='width:160px;background-color:#00DD00;height:6px;font-size:4px'>&nbsp;</div></div>Excellent";
        }
    }
}
