🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

secure-random-password

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

secure-random-password - npm Package Compare versions

Comparing version

to
0.2.3

2

dist/secure-random-password.min.js

@@ -1,1 +0,1 @@

!function(r){var t={};function e(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var o in r)e.d(n,o,function(t){return r[t]}.bind(null,o));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=2)}([function(r,t){r.exports={}},function(r,t,e){"use strict";function n(r){return Array.apply(null,Array(r)).map((function(r,t){return t}))}function o(r){return Array.prototype.slice.call(r)}t.assign=function(){var r=o(arguments),t=r[0],e=r.slice(1);return e.filter((function(r){return!!r})).forEach((function(r){Object.keys(r).forEach((function(e){t[e]=r[e]}))})),t},t.intersection=function(r,t){r=o(r),t=o(t);var e={};r.forEach((function(r){e[r]=!0}));var n={};return t.forEach((function(r){n[r]=!0})),Object.keys(e).filter((function(r){return Object.prototype.hasOwnProperty.call(n,r)}))},t.isInteger=function(r){return"number"==typeof r&&isFinite(r)&&Math.floor(r)===r},t.isString=function(r){return"string"==typeof r||r instanceof String},t.range=n,t.repeat=function(r,t){return n(t).map((function(){return r}))},t.toArray=o},function(r,t,e){window.secureRandomPassword=e(3)},function(r,t,e){"use strict";var n=e(4).default,o=e(7),u=e(1);Object.keys(o).forEach((function(r){t[r]=o[r]}));var i=["Il1|","O0"];function a(r){var t={avoidAmbiguous:!0,characters:[o.lower,{characters:o.upper,exactly:1},{characters:o.symbols,exactly:1}],length:12,predicate:function(){return!0},random:n},e=function(r){if(!r.characters)return[];var t=Array.isArray(r.characters)?r.characters:[r.characters];t=t.map((function(r){return u.isString(r)?{characters:r}:r}));var e=!0===r.avoidAmbiguous?i:r.avoidAmbiguous||[];return function(r,t){var e=r.map((function(r){return r.characters})).join(""),n=t.filter((function(r){return u.intersection(r,e).length>1})).join("");r.forEach((function(r){r.characters=u.toArray(r.characters).filter((function(r){return n.indexOf(r)<0})).join("")}))}(t,e),t}(r=u.assign({},t,r));if(!u.isInteger(r.length))throw new Error("length must be an integer");if(r.length<1)throw new Error("length must be > 0");if(r.length<e.length)throw new Error("length must be >= # of character sets passed");if(e.some((function(r){return!r.characters})))throw new Error("No character set may be empty");if(0===e.length)throw new Error("Must pass one or more character sets");if("function"!=typeof r.predicate)throw new Error("predicate must be a function");var a,s=e.map((function(r){return r.exactly||1})).reduce((function(r,t){return r+t}),0);if(r.length<s)throw new Error("length is too short for character set rules");if(e.every((function(r){return r.exactly}))&&e.reduce((function(r,t){return r.exactly+t.exactly}),0)!==r.length)throw new Error("Must pass a set without exactly rule to generate the specified length");do{a=c(e,r.length,r.random)}while(!r.predicate(a));return a}function c(r,t,e){var n=r.map((function(r){return r.exactly?u.repeat(r.characters,r.exactly):[r.characters]})).reduce((function(r,t){return r.concat(t)})).map((function(r){return e.choose(r)})),o=r.filter((function(r){return!r.exactly})).map((function(r){return r.characters})).join(""),i=u.range(t-n.length).map((function(){return e.choose(o)}));return e.shuffle(n.concat(i)).join("")}t.randomPassword=a,t.randomString=function(r){var t={characters:[o.lower,o.upper,o.digits,o.symbols],length:20};return(r=u.assign({},t,r)).avoidAmbiguous=!1,a(r)}},function(r,t,e){"use strict";var n=e(5),o=e(1);function u(r){if("function"!=typeof r)throw new Error("Must pass a randomSource function");this._randomSource=r}function i(r){for(var t=0,e=1,n=(r=r||[]).length-1;n>=0;n--)t+=r[n]*e,e*=256;return t}u.prototype.choose=function(r){if(!r||!r.length)throw new Error("Must pass 1 or more choices");return r[this._getInt(r.length)]},u.prototype.getInt=function(r){if(void 0===r)throw new Error("Must pass an upper bound");if(!o.isInteger(r))throw new Error("Upper bound must be a number");if(r<1)throw new Error("Upper bound must be > 0");return this._getInt(r)},u.prototype._getInt=function(r){if(1===r)return 0;var t,e=Math.ceil(Math.log(r)/Math.log(256)),n=Math.pow(2,8*e)-Math.pow(2,8*e)%r;do{t=i(this._randomSource(e))}while(t>=n);return t%r},u.prototype.shuffle=function(r){r=Array.prototype.slice.call(r||[]);for(var t=[];r.length;)t.push(r.splice(this._getInt(r.length),1)[0]);return t},t.Random=u,t.default=new u(n)},function(r,t,e){(function(n,o){var u;!function(i){"use strict";function a(r,t){if(t=t||{type:"Array"},void 0!==n&&"number"==typeof n.pid&&n.versions&&n.versions.node)return function(r,t){var n=e(6).randomBytes(r);switch(t.type){case"Array":return[].slice.call(n);case"Buffer":return n;case"Uint8Array":for(var o=new Uint8Array(r),u=0;u<r;++u)o[u]=n.readUInt8(u);return o;default:throw new Error(t.type+" is unsupported.")}}(r,t);if(!(window.crypto||window.msCrypto))throw new Error("Your browser does not support window.crypto.");return function(r,t){var e=new Uint8Array(r);switch((window.crypto||window.msCrypto).getRandomValues(e),t.type){case"Array":return[].slice.call(e);case"Buffer":try{new o(1)}catch(r){throw new Error("Buffer not supported in this environment. Use Node.js or Browserify for browser support.")}return new o(e);case"Uint8Array":return e;default:throw new Error(t.type+" is unsupported.")}}(r,t)}void 0===(u=function(){return a}.apply(t,[]))||(r.exports=u),a.randomArray=function(r){return a(r,{type:"Array"})},a.randomUint8Array=function(r){return a(r,{type:"Uint8Array"})},a.randomBuffer=function(r){return a(r,{type:"Buffer"})}}()}).call(this,e(0),e(0).Buffer)},function(r,t){},function(r,t){t.lower="abcdefghijklmnopqrstuvwxyz",t.upper=t.lower.toUpperCase(),t.consonants="bcdfghjklmnpqrstvwxyz",t.vowels="aeiou",t.digits="1234567890",t.symbols="!@#$%^&*()",t.fullSymbols="!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",t.copyableSymbols="_"}]);
(()=>{var r={10:(r,t,e)=>{"use strict";var n=e(744).Z,o=e(505),a=e(502);Object.keys(o).forEach((function(r){t[r]=o[r]}));var c=["Il1|","O0"];function u(r){var t={avoidAmbiguous:!0,characters:[o.lower,{characters:o.upper,exactly:1},{characters:o.symbols,exactly:1}],length:12,predicate:function(){return!0},random:n},e=function(r){if(!r.characters)return[];var t=Array.isArray(r.characters)?r.characters:[r.characters];return function(r,t){var e=r.map((function(r){return r.characters})).join(""),n=t.filter((function(r){return a.intersection(r,e).length>1})).join("");r.forEach((function(r){r.characters=a.toArray(r.characters).filter((function(r){return n.indexOf(r)<0})).join("")}))}(t=t.map((function(r){return a.isString(r)?{characters:r}:r})),!0===r.avoidAmbiguous?c:r.avoidAmbiguous||[]),t}(r=a.assign({},t,r));if(!a.isInteger(r.length))throw new Error("length must be an integer");if(r.length<1)throw new Error("length must be > 0");if(r.length<e.length)throw new Error("length must be >= # of character sets passed");if(e.some((function(r){return!r.characters})))throw new Error("No character set may be empty");if(0===e.length)throw new Error("Must pass one or more character sets");if("function"!=typeof r.predicate)throw new Error("predicate must be a function");var u,s=e.map((function(r){return r.exactly||1})).reduce((function(r,t){return r+t}),0);if(r.length<s)throw new Error("length is too short for character set rules");if(e.every((function(r){return r.exactly}))&&e.reduce((function(r,t){return r+t.exactly}),0)!==r.length)throw new Error("Must pass a set without exactly rule to generate the specified length");do{u=i(e,r.length,r.random)}while(!r.predicate(u));return u}function i(r,t,e){var n=r.map((function(r){return r.exactly?a.repeat(r.characters,r.exactly):[r.characters]})).reduce((function(r,t){return r.concat(t)})).map((function(r){return e.choose(r)})),o=r.filter((function(r){return!r.exactly})).map((function(r){return r.characters})).join(""),c=a.range(t-n.length).map((function(){return e.choose(o)}));return e.shuffle(n.concat(c)).join("")}t.randomPassword=u,t.randomString=function(r){var t={characters:[o.lower,o.upper,o.digits,o.symbols],length:20};return(r=a.assign({},t,r)).avoidAmbiguous=!1,u(r)}},505:(r,t)=>{t.lower="abcdefghijklmnopqrstuvwxyz",t.upper=t.lower.toUpperCase(),t.consonants="bcdfghjklmnpqrstvwxyz",t.vowels="aeiou",t.digits="1234567890",t.symbols="!@#$%^&*()",t.fullSymbols="!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",t.copyableSymbols="_"},744:(r,t,e)=>{"use strict";var n=e(64),o=e(502);function a(r){if("function"!=typeof r)throw new Error("Must pass a randomSource function");this._randomSource=r}function c(r){for(var t=0,e=1,n=(r=r||[]).length-1;n>=0;n--)t+=r[n]*e,e*=256;return t}a.prototype.choose=function(r){if(!r||!r.length)throw new Error("Must pass 1 or more choices");return r[this._getInt(r.length)]},a.prototype.getInt=function(r){if(void 0===r)throw new Error("Must pass an upper bound");if(!o.isInteger(r))throw new Error("Upper bound must be a number");if(r<1)throw new Error("Upper bound must be > 0");return this._getInt(r)},a.prototype._getInt=function(r){if(1===r)return 0;var t,e=Math.ceil(Math.log(r)/Math.log(256)),n=Math.pow(2,8*e)-Math.pow(2,8*e)%r;do{t=c(this._randomSource(e))}while(t>=n);return t%r},a.prototype.shuffle=function(r){r=Array.prototype.slice.call(r||[]);for(var t=[];r.length;)t.push(r.splice(this._getInt(r.length),1)[0]);return t},t.Z=new a(n)},502:(r,t)=>{"use strict";function e(r){return Array.apply(null,Array(r)).map((function(r,t){return t}))}function n(r){return Array.prototype.slice.call(r)}t.assign=function(){var r=n(arguments),t=r[0],e=r.slice(1);return e.filter((function(r){return!!r})).forEach((function(r){Object.keys(r).forEach((function(e){t[e]=r[e]}))})),t},t.intersection=function(r,t){r=n(r),t=n(t);var e={};r.forEach((function(r){e[r]=!0}));var o={};return t.forEach((function(r){o[r]=!0})),Object.keys(e).filter((function(r){return Object.prototype.hasOwnProperty.call(o,r)}))},t.isInteger=function(r){return"number"==typeof r&&isFinite(r)&&Math.floor(r)===r},t.isString=function(r){return"string"==typeof r||r instanceof String},t.range=e,t.repeat=function(r,t){return e(t).map((function(){return r}))},t.toArray=n},64:function(r,t,e){var n;!function(o){"use strict";function a(r,t){if(t=t||{type:"Array"},"undefined"!=typeof process&&"number"==typeof process.pid&&process.versions&&process.versions.node)return function(r,t){var n=e(954).randomBytes(r);switch(t.type){case"Array":return[].slice.call(n);case"Buffer":return n;case"Uint8Array":for(var o=new Uint8Array(r),a=0;a<r;++a)o[a]=n.readUInt8(a);return o;default:throw new Error(t.type+" is unsupported.")}}(r,t);if(!window.crypto&&!window.msCrypto)throw new Error("Your browser does not support window.crypto.");return function(r,t){var e=new Uint8Array(r);switch((window.crypto||window.msCrypto).getRandomValues(e),t.type){case"Array":return[].slice.call(e);case"Buffer":try{new Buffer(1)}catch(r){throw new Error("Buffer not supported in this environment. Use Node.js or Browserify for browser support.")}return new Buffer(e);case"Uint8Array":return e;default:throw new Error(t.type+" is unsupported.")}}(r,t)}void 0===(n=function(){return a}.apply(t,[]))||(r.exports=n),a.randomArray=function(r){return a(r,{type:"Array"})},a.randomUint8Array=function(r){return a(r,{type:"Uint8Array"})},a.randomBuffer=function(r){return a(r,{type:"Buffer"})}}()},954:()=>{}},t={};window.secureRandomPassword=function e(n){var o=t[n];if(void 0!==o)return o.exports;var a=t[n]={exports:{}};return r[n].call(a.exports,a,a.exports,e),a.exports}(10)})();

@@ -60,3 +60,3 @@ 'use strict';

if (allExactly) {
var exactlyLength = characterRules.reduce(function (l, r) { return l.exactly + r.exactly }, 0);
var exactlyLength = characterRules.reduce(function (acc, r) { return acc + r.exactly }, 0);
if (exactlyLength !== opts.length) {

@@ -63,0 +63,0 @@ throw new Error('Must pass a set without exactly rule to generate the specified length');

@@ -196,2 +196,19 @@ const randomPassword = require('./index').randomPassword;

});
it('accepts a totaled number of exactly character sets + required sets', () => {
expect(() => randomPassword({
length: 10,
characters: [
{ characters: '123', exactly: 10 }
]
})).not.toThrow();
expect(() => randomPassword({
length: 30,
characters: [
{ characters: '123', exactly: 10 },
{ characters: '123', exactly: 20 }
]
})).not.toThrow();
});
});

@@ -198,0 +215,0 @@

{
"name": "secure-random-password",
"version": "0.2.2",
"version": "0.2.3",
"description": "Generate passwords using a cryptographically-strong source of randomness",

@@ -29,7 +29,7 @@ "main": "index.js",

"devDependencies": {
"eslint": "^6.8.0",
"jest": "^24.9.0",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.12"
"eslint": "^7.28.0",
"jest": "^27.0.4",
"webpack": "^5.38.1",
"webpack-cli": "^4.7.2"
}
}