password-generator
Advanced tools
Comparing version 0.1.3 to 0.2.0
@@ -25,9 +25,9 @@ var argv, fs, optimist, path, puts; | ||
this.run = function() { | ||
this.run = function () { | ||
var generatePassword = require('./password-generator'), | ||
pattern = argv.p || null; | ||
pattern = argv.p || null; | ||
if (argv.h) { | ||
return optimist.showHelp(); | ||
} | ||
if(pattern){ | ||
if (pattern) { | ||
pattern = new RegExp(pattern); | ||
@@ -34,0 +34,0 @@ argv.c = false; |
@@ -1,49 +0,65 @@ | ||
/*! | ||
/* | ||
* password-generator | ||
* Copyright(c) 2011 Bermi Ferrer <bermi@bermilabs.com> | ||
* Copyright(c) 2011-2013 Bermi Ferrer <bermi@bermilabs.com> | ||
* MIT Licensed | ||
*/ | ||
(function (root) { | ||
var consonant, letter, password, vowel; | ||
letter = /[a-zA-Z]$/; | ||
vowel = /[aeiouAEIOU]$/; | ||
consonant = /[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]$/; | ||
var localName, consonant, letter, password, vowel; | ||
letter = /[a-zA-Z]$/; | ||
vowel = /[aeiouAEIOU]$/; | ||
consonant = /[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]$/; | ||
module.exports = password = function(length, memorable, pattern, prefix) { | ||
var char, n; | ||
if (length == null) { | ||
length = 10; | ||
} | ||
if (memorable == null) { | ||
memorable = true; | ||
} | ||
if (pattern == null) { | ||
pattern = /\w/; | ||
} | ||
if (prefix == null) { | ||
prefix = ''; | ||
} | ||
if (prefix.length >= length) { | ||
return prefix; | ||
} | ||
if (memorable) { | ||
if (prefix.match(consonant)) { | ||
pattern = vowel; | ||
} else { | ||
pattern = consonant; | ||
// Defines the name of the local variable the passwordGenerator library will use | ||
// this is specially useful if window.passwordGenerator is already being used | ||
// by your application and you want a different name. For example: | ||
// // Declare before including the passwordGenerator library | ||
// var localPasswordGeneratorLibraryName = 'pass'; | ||
localName = root.localPasswordGeneratorLibraryName || "generatePassword", | ||
password = function (length, memorable, pattern, prefix) { | ||
var char, n; | ||
if (length == null) { | ||
length = 10; | ||
} | ||
if (memorable == null) { | ||
memorable = true; | ||
} | ||
if (pattern == null) { | ||
pattern = /\w/; | ||
} | ||
if (prefix == null) { | ||
prefix = ''; | ||
} | ||
if (prefix.length >= length) { | ||
return prefix; | ||
} | ||
if (memorable) { | ||
if (prefix.match(consonant)) { | ||
pattern = vowel; | ||
} else { | ||
pattern = consonant; | ||
} | ||
} | ||
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); | ||
}; | ||
((typeof exports !== 'undefined') ? exports : root)[localName] = password; | ||
if (typeof exports !== 'undefined') { | ||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = password; | ||
} | ||
} | ||
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); | ||
}; | ||
/** | ||
* Version. | ||
*/ | ||
exports.version = '0.1.3'; | ||
// Establish the root object, `window` in the browser, or `global` on the server. | ||
}(this)); |
{ | ||
"name": "password-generator", | ||
"version": "0.1.3", | ||
"description": "Memorable password generator", | ||
"version": "0.2.0", | ||
"description": "Memorable password generator. For the command line, Node.js and the browser.", | ||
"author": "Bermi Ferrer <bermi@bermilabs.com>", | ||
"keywords": [ | ||
"password", | ||
"generator", | ||
"pass", | ||
"random" | ||
"password", | ||
"generator", | ||
"pass", | ||
"random", | ||
"browser", | ||
"security" | ||
], | ||
"bugs": { | ||
"web": "http://github.com/bermi/password-generator/issues" | ||
"web": "http://github.com/bermi/password-generator/issues" | ||
}, | ||
@@ -22,7 +24,7 @@ "licenses": [ | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/bermi/password-generator.git" | ||
"type": "git", | ||
"url": "git://github.com/bermi/password-generator.git" | ||
}, | ||
"engines": { | ||
"node": ">= 0.4.x" | ||
"node": ">= 0.6.x" | ||
}, | ||
@@ -33,3 +35,5 @@ "dependencies": { | ||
"devDependencies": { | ||
"expresso" : ">= 0.9.x" | ||
"mocha": "*", | ||
"grunt": "*", | ||
"expect.js": "*" | ||
}, | ||
@@ -42,4 +46,4 @@ "scripts": { | ||
"directories": { | ||
"lib": "./lib" | ||
"lib": "./lib" | ||
} | ||
} | ||
} |
@@ -5,3 +5,3 @@ # password-generator | ||
Memorable password generator. | ||
Memorable password generator. For the command line, Node.js and browsers. | ||
@@ -21,3 +21,3 @@ ## Installation | ||
Generates a memorable password | ||
Options: | ||
@@ -60,19 +60,25 @@ -l Password length | ||
### From node.js | ||
### From Node.js | ||
var generatePassword = require('password-generator'); | ||
Default settings (memorable 10 letters) | ||
### From the browser | ||
<script src="https://raw.github.com/bermi/password-generator/master/dist/password-generator.min.js" type="text/javascript"></script> | ||
#### Usage | ||
##### Default settings (memorable 10 letters) | ||
generatePassword() // -> xexeyimahi | ||
Custom length not memorable | ||
##### Custom length not memorable | ||
generatePassword(12, false) // -> 76PAGEaq6i5c | ||
Characters should match a pattern | ||
##### Characters should match a pattern | ||
generatePassword(12, false, /\d/) // -> 252667390298 | ||
Customize the password prefix | ||
##### Customize the password prefix | ||
@@ -85,7 +91,11 @@ generatePassword(12, false, /\d/, 'foo-') // -> foo-67390298 | ||
npm install | ||
make test | ||
## License | ||
## Building | ||
npm install | ||
make all | ||
## License | ||
(The MIT License) | ||
@@ -92,0 +102,0 @@ |
@@ -0,30 +1,36 @@ | ||
(function (root) { | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var expect = root.expect || require('expect.js'), | ||
generatePassword; | ||
var assert = require('assert'), | ||
// This test is meant to run in both, the browser and the CLI | ||
if (typeof window === 'undefined') { | ||
generatePassword = require('../'); | ||
} else { | ||
generatePassword = root.generatePassword; | ||
} | ||
module.exports = { | ||
'should generate a 10 chararacter memorable password': function(){ | ||
assert.ok(generatePassword().match(/([bcdfghjklmnpqrstvwxyz][aeiou]){5}/)); | ||
}, | ||
'should generate a 6 chararacter memorable password': function(){ | ||
assert.ok(generatePassword().match(/([bcdfghjklmnpqrstvwxyz][aeiou]){3}/)); | ||
}, | ||
'should generate a 1000 chararacter non memorable password': function(){ | ||
var pass = generatePassword(1000, false); | ||
assert.ok(pass.match(/[bcdfghjklmnpqrstvwxyz]{4}/ig)); | ||
assert.ok(pass.length === 1000); | ||
}, | ||
'should generate passwords matching regex pattern': function(){ | ||
var pass = generatePassword(5, false, /\d/); | ||
assert.ok(pass.match(/^\d{5}$/)); | ||
}, | ||
'should generate passwords with a given preffix': function(){ | ||
var pass = generatePassword(7, false, /\d/, 'foo-'); | ||
assert.ok(pass.match(/^foo\-\d{3}$/)); | ||
} | ||
}; | ||
describe("When using the password generator, it:", function () { | ||
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 () { | ||
var pass = generatePassword(1000, false); | ||
expect(pass).to.match(/[bcdfghjklmnpqrstvwxyz]{4}/ig); | ||
expect(pass.length).to.be(1000); | ||
}); | ||
it('should generate passwords matching regex pattern', function () { | ||
var pass = generatePassword(5, false, /\d/); | ||
expect(pass).to.match(/^\d{5}$/); | ||
}); | ||
it('should generate passwords with a given preffix', function () { | ||
var pass = generatePassword(7, false, /\d/, 'foo-'); | ||
expect(pass).to.match(/^foo\-\d{3}$/); | ||
}); | ||
}); | ||
}(this)); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
32985
18
247
118
3