Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

password-generator

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

password-generator - npm Package Compare versions

Comparing version 0.2.4 to 1.0.0

61

dist/password-generator.js
/*
* password-generator
* Copyright(c) 2011-2013 Bermi Ferrer <bermi@bermilabs.com>
* Copyright(c) 2011-2015 Bermi Ferrer <bermi@bermilabs.com>
* MIT Licensed

@@ -22,3 +22,3 @@ */

password = function (length, memorable, pattern, prefix) {
var char, n;
var char = "", n, i, validChars = [];
if (length == null) {

@@ -36,24 +36,49 @@ length = 10;

}
if (prefix.length >= length) {
return prefix;
// Non memorable passwords will pick characters from a pre-generated
// list of characters
if (!memorable) {
for (i = 33; 126 > i; i += 1) {
char = String.fromCharCode(i);
if (char.match(pattern)) {
validChars.push(char);
}
}
if (!validChars.length) {
throw new Error("Could not find characters that match the " +
"password pattern " + pattern + ". Patterns must match individual " +
"characters, not the password as a whole.");
}
}
if (memorable) {
if (prefix.match(consonant)) {
pattern = vowel;
while (prefix.length < length) {
if (memorable) {
if (prefix.match(consonant)) {
pattern = vowel;
} else {
pattern = consonant;
}
n = rand(33, 126);
char = String.fromCharCode(n);
} else {
pattern = consonant;
char = validChars[rand(0, validChars.length)];
}
if (memorable) {
char = char.toLowerCase();
}
if (char.match(pattern)) {
prefix = "" + prefix + char;
}
}
n = (Math.floor(Math.random() * 100) % 94) + 33;
char = String.fromCharCode(n);
if (memorable) {
char = char.toLowerCase();
}
if (!char.match(pattern)) {
return password(length, memorable, pattern, prefix);
}
return password(length, memorable, pattern, "" + prefix + char);
return prefix;
};
function rand(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
((typeof exports !== 'undefined') ? exports : root)[localName] = password;

@@ -67,2 +92,2 @@ if (typeof exports !== 'undefined') {

// Establish the root object, `window` in the browser, or `global` on the server.
}(this));
}(this));

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

/*! password-generator - v0.2.1 (2013-04-28)
/*! password-generator - v1.0.0 (2015-05-22)
* -----------------
* Copyright(c) 2013 Bermi Ferrer <bermi@bermilabs.com>
* Copyright(c) 2011-2015 Bermi Ferrer <bermi@bermilabs.com>
* MIT Licensed
*/
(function(e){var t,n,r,i,s;r=/[a-zA-Z]$/,s=/[aeiouAEIOU]$/,n=/[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]$/,t=e.localPasswordGeneratorLibraryName||"generatePassword",i=function(e,t,r,o){var u,a;return e==null&&(e=10),t==null&&(t=!0),r==null&&(r=/\w/),o==null&&(o=""),o.length>=e?o:(t&&(o.match(n)?r=s:r=n),a=Math.floor(Math.random()*100)%94+33,u=String.fromCharCode(a),t&&(u=u.toLowerCase()),u.match(r)?i(e,t,r,""+o+u):i(e,t,r,o))},(typeof exports!="undefined"?exports:e)[t]=i,typeof exports!="undefined"&&typeof module!="undefined"&&module.exports&&(module.exports=i)})(this);
(function(e){function o(e,t){return Math.floor(Math.random()*(t-e)+e)}var t,n,r,i,s;r=/[a-zA-Z]$/,s=/[aeiouAEIOU]$/,n=/[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]$/,t=e.localPasswordGeneratorLibraryName||"generatePassword",i=function(e,t,r,i){var u="",a,f,l=[];e==null&&(e=10),t==null&&(t=!0),r==null&&(r=/\w/),i==null&&(i="");if(!t){for(f=33;126>f;f+=1)u=String.fromCharCode(f),u.match(r)&&l.push(u);if(!l.length)throw new Error("Could not find characters that match the password pattern "+r+". Patterns must match individual "+"characters, not the password as a whole.")}while(i.length<e)t?(i.match(n)?r=s:r=n,a=o(33,126),u=String.fromCharCode(a)):u=l[o(0,l.length)],t&&(u=u.toLowerCase()),u.match(r)&&(i=""+i+u);return i},(typeof exports!="undefined"?exports:e)[t]=i,typeof exports!="undefined"&&typeof module!="undefined"&&module.exports&&(module.exports=i)})(this);

@@ -50,3 +50,3 @@ module.exports = function (grunt) {

"\n* -----------------\n" +
"* Copyright(c) 2013 Bermi Ferrer <bermi@bermilabs.com>\n" +
"* Copyright(c) 2011-2015 Bermi Ferrer <bermi@bermilabs.com>\n" +
"* MIT Licensed\n*/"

@@ -53,0 +53,0 @@ },

/*
* password-generator
* Copyright(c) 2011-2013 Bermi Ferrer <bermi@bermilabs.com>
* Copyright(c) 2011-2015 Bermi Ferrer <bermi@bermilabs.com>
* MIT Licensed

@@ -22,3 +22,3 @@ */

password = function (length, memorable, pattern, prefix) {
var char = "", n;
var char = "", n, i, validChars = [];
if (length == null) {

@@ -36,2 +36,21 @@ length = 10;

}
// Non memorable passwords will pick characters from a pre-generated
// list of characters
if (!memorable) {
for (i = 33; 126 > i; i += 1) {
char = String.fromCharCode(i);
if (char.match(pattern)) {
validChars.push(char);
}
}
if (!validChars.length) {
throw new Error("Could not find characters that match the " +
"password pattern " + pattern + ". Patterns must match individual " +
"characters, not the password as a whole.");
}
}
while (prefix.length < length) {

@@ -44,6 +63,8 @@ if (memorable) {

}
n = rand(33, 126);
char = String.fromCharCode(n);
} else {
char = validChars[rand(0, validChars.length)];
}
n = Math.floor(Math.random() * 94) + 33;
char = String.fromCharCode(n);
if (memorable) {

@@ -57,6 +78,9 @@ char = char.toLowerCase();

return prefix;
// return password(length, memorable, pattern, "" + prefix + char);
};
function rand(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
((typeof exports !== 'undefined') ? exports : root)[localName] = password;

@@ -63,0 +87,0 @@ if (typeof exports !== 'undefined') {

{
"name": "password-generator",
"version": "0.2.4",
"version": "1.0.0",
"description": "Memorable password generator. For the command line, Node.js and the browser.",

@@ -28,8 +28,8 @@ "author": "Bermi Ferrer <bermi@bermilabs.com>",

"dependencies": {
"optimist": "*"
"optimist": "0.6.1"
},
"devDependencies": {
"mocha": "~1.9.0",
"expect.js": "~0.2.0",
"grunt": "~0.3.x"
"expect.js": "0.2.0",
"grunt": "0.3.17",
"mocha": "2.2.5"
},

@@ -36,0 +36,0 @@ "scripts": {

@@ -15,8 +15,14 @@ (function (root) {

describe("When using the password generator, it:", function () {
this.timeout(20);
it('should generate a 10 chararacter memorable password', function () {
expect(generatePassword()).to.match(/([bcdfghjklmnpqrstvwxyz][aeiou]){5}/);
});
it('should generate a 6 chararacter memorable password', function () {
expect(generatePassword()).to.match(/([bcdfghjklmnpqrstvwxyz][aeiou]){3}/);
});
it('should generate a 1000 chararacter non memorable password', function () {

@@ -27,2 +33,4 @@ var pass = generatePassword(1000, false);

});
it('should generate passwords matching regex pattern', function () {

@@ -32,2 +40,4 @@ var pass = generatePassword(5, false, /\d/);

});
it('should generate passwords with a given preffix', function () {

@@ -37,9 +47,25 @@ var pass = generatePassword(7, false, /\d/, 'foo-');

});
it('should generate long passwords without throwing exceeding the ' +
'call stack limits' , function () {
it('should generate long passwords without throwing call stack limit exceptions', function () {
var pass = generatePassword(1200, false, /\d/);
expect(pass).to.match(/^\d{1200}$/);
});
it('should generate passwords with a very short /(t|e|s|t)/ pattern', function () {
var pass = generatePassword(11, false, /(t|e|s|t)/);
expect(pass.length).to.be(11);
expect(pass).to.match(/(t|e|s|t)/);
});
it('should prevent using invalid patterns', function () {
expect(function () {
generatePassword(11, false, /test/);
}).to.throwException(/Could not find characters that match the password pattern/);
});
});
}(this));

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc