-
Notifications
You must be signed in to change notification settings - Fork 1
/
master.js
2 lines (2 loc) · 3.21 KB
/
master.js
1
2
"use strict";function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),PasswordGen=function(){function e(){_classCallCheck(this,e),this.passwordLength=this.constructor.DEFAULTLENGTH,this.keyspace="",this.generateKeyspace()}return _createClass(e,[{key:"errorTooLarge",value:function(e){return"Sorry the "+e+" is too large\nThe maximum size is "+this.constructor.MAXIMUMRANDOMINTEGER+"\nThe default "+e+" is currently being used"}},{key:"errorTooLong",value:function(e){return"Sorry the "+e+" is too long\nThe maximum length is "+this.constructor.MAXIMUMRANDOMINTEGER+" characters\nThe default "+e+" is currently being used"}},{key:"setLength",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return e===parseInt(e)&&e>=this.constructor.MINIMUMLENGTH&&(this.passwordLength=e),this}},{key:"setKeyspace",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return"string"==typeof e&&""!==e&&(e.length<this.constructor.MAXIMUMRANDOMINTEGER?this.keyspace=e:console.log(this.errorTooLong("keyspace"))),this}},{key:"generateKeyspace",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:this.constructor.DEFAULTSETS;this.keyspace="",("string"!=typeof e||this.constructor.arrayKeySearch(e,this.constructor.CHARACTERSETS))&&(e=this.constructor.DEFAULTSETS);for(var t in e.split(""))e.hasOwnProperty(t)&&(this.keyspace+=this.constructor.CHARACTERSETS[e[t]]);return this.keyspace.length>this.constructor.MAXIMUMRANDOMINTEGER&&(console.log(this.errorTooLong("keyspace")),this.generateKeyspace()),this}},{key:"generatePassword",value:function(){for(var e="",t=0;t<this.passwordLength;t++)e+=this.keyspace.split("")[this.constructor.randomInteger(0,this.keyspace.length-1)];return e}},{key:"password",get:function(){return this.generatePassword()}}],[{key:"arrayKeySearch",value:function(e,t){for(var r=0,n=e.length;r<n;){for(var o in t)if(t.hasOwnProperty(o)&&e[r]===o)return!0;r++}return!1}},{key:"randomInteger",value:function(e,t){try{if(t<256){var r=window.crypto||window.msCrypto,n=new Uint8Array(1);r.getRandomValues(n);var o=t-e+1;return n[0]>=Math.floor(256/o)*o?this.randomInteger(e,t):e+n[0]%o}throw"Sorry the maximum is too large\nThe maximum size is 256\n"}catch(e){console.log(e)}}},{key:"MINIMUMLENGTH",get:function(){return 8}},{key:"MAXIMUMRANDOMINTEGER",get:function(){return 256}},{key:"DEFAULTLENGTH",get:function(){return 16}},{key:"DEFAULTSETS",get:function(){return"luns"}},{key:"LOWERCASELETTERS",get:function(){return"abcdefghijklmnopqrstuvwxyz"}},{key:"UPPERCASELETTERS",get:function(){return"ABCDEFGHIJKLMNOPQRSTUVWXYZ"}},{key:"NUMBERS",get:function(){return"1234567890"}},{key:"SPECIALCHARACTERS",get:function(){return"!@#$%&*?,./|[]{}()"}},{key:"WHITESPACE",get:function(){return" "}},{key:"CHARACTERSETS",get:function(){return{l:this.LOWERCASELETTERS,u:this.UPPERCASELETTERS,n:this.NUMBERS,s:this.SPECIALCHARACTERS,w:this.WHITESPACE}}}]),e}();
//# sourceMappingURL=master.js.map