Home > OS >  How do I make a key generator for my website? Using Javascript or Html [closed]
How do I make a key generator for my website? Using Javascript or Html [closed]

Time:09-24

I was making a website using Html, CSS, And some Javascript. But I was wondering how do I make a key gen using Html, or More likely Javascript Or if so CSS?

CodePudding user response:

If its just random letters and numbers use this function:

function getKey(length = 10) {
    const getRandomInt = (min, max) =>  {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min   1))   min;
}
    const characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    let randomString = '';
    for (let i = 0; i < length; i  ) {
        randomString  = characters[getRandomInt(0, characters.length - 1)];
    }
    return randomString;
}

console.log(getKey(32));

CodePudding user response:

$('button').click(()=>{

    let key = keyGen();
  $('#key').text(key);

});

function keyGen() {
    return (
      Math.random().toString(36).substring(2, 15)  
      Math.random().toString(36).substring(2, 15)  
      Math.random().toString(36).substring(2, 15)
    );
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button>
Generate key
</button>

<div id="key">
  ....
</div>

  • Related