Generate Key from letter and digit - Node.js Security

Node.js examples for Security:GUID

Description

Generate Key from letter and digit

Demo Code

var KeyGen = new function() {
  this.generateKey = function() {
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var string_length = 8;
    var randomstring = '';
    for (var i=0; i<string_length; i++) {
      var rnum = Math.floor(Math.random() * chars.length);
      randomstring += chars.substring(rnum,rnum+1);
    }/*from   w w w  . j av  a2s. co  m*/
    return randomstring;
  }
}

Related Tutorials