Литмир - Электронная Библиотека

var l=document.querySelector(".l");

var n=document.querySelector(".n");

var us=document.querySelector(".us");

var s=document.querySelector(".s");

var buttonCalc=document.querySelector(".buttoncalc");

var buttonClear=document.querySelector(".buttonclear");

var alert=document.querySelector(".alert");

var ta=document.querySelector(".ta");

buttonCalc.addEventListener("click",showResult);

buttonClear.addEventListener("click",clear);

function showResult(){

    var pasLength=0;

    var pasQuantitet=0;

    var argument="";

    var pas="";

    var multiPas="";

    if (isNullInField(l.value)){

        alert.textContent="enter the length of the password";

        alert.style.color="red";

        l.focus();

        return;

    }

    if (isNullInField(n.value)){

        alert.textContent="enter the number of passwords";

        alert.style.color="red";

        n.focus();

        return;

    }

    pasLength=Number(l.value);

    pasQuantitet=Number(n.value);

    if(pasLength<1||pasLength>1000){

            alert.textContent="The password must be between 1 and 1000 characters in length";

            alert.style.color="red";

            l.focus();

            return;  

        }

         if(pasQuantitet<1||pasQuantitet>100){

             alert.textContent="The number of passwords must be from 1 to 100";

             alert.style.color="red";

             n.focus();

             return;

         }

         alert.textContent="";

          if(isNullInField(us.value)){

           argument=combinations(s.selectedIndex);

        }else{

           argument=us.value;

         }

         for(var i=0;i<pasQuantitet;i++){

             pas=passwordCreator(argument,pasLength);

             if(pas===""){

                 alert.textContent="Remove all spaces!";

                 alert.style.color="red";

                 us.focus();

                 return;

             }else{

                alert.textContent="";

             }

             multiPas+=pas+"\n";

         }

         ta.textContent=multiPas;

}

function passwordCreator(s,q){

      var  str="";

      var masSymbols=[];

                masSymbols=s.split("");

                for (var i=0;i<s.length;i++){

                    if (masSymbols[i]===" "){

                        return "";

                    }

                }

                for (var i=0;i<q;i++){

                    str+=masSymbols[Math.floor(Math.random() * s.length)]+"";

                }

        return str;

}

function combinations(m){

    var str;

    switch (m){

        case 0:

            str="abcdefghijklmnopqrstuvwxyz";

            break;

            case 1:

                str="0123456789";

                break;

                case 2:

                    str="abcdefghijklmnopqrstuvwxyz0123456789";

                    break;

                    default :

                        break;

    }

    return str;

}

function clear(){

2
{"b":"602419","o":1}