Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit b25cab25449ae462cd57eeb996c889fa5c2c11b8 @bermi committed Oct 3, 2011
Showing with 162 additions and 0 deletions.
  1. +4 −0 HISTORY.md
  2. +16 −0 Makefile
  3. +53 −0 README.md
  4. +1 −0 index.js
  5. +49 −0 lib/password-generator.js
  6. +9 −0 package.json
  7. +30 −0 test/password-generator.test.js
@@ -0,0 +1,4 @@
+0.0.1 / 2011-04-24
+==================
+
+ * Initial release
@@ -0,0 +1,16 @@
+
+DOCS = $(shell find docs/*.md)
+HTMLDOCS =$(DOCS:.md=.html)
+
+test:
+ @NODE_ENV=test expresso \
+ -I lib \
+ -I support \
+ $(TESTFLAGS) \
+ test/*.test.js
+
+test-cov:
+ @TESTFLAGS=--cov $(MAKE) test
+
+
+.PHONY: test test-cov
@@ -0,0 +1,53 @@
+# password-generator
+
+Memorable password generator.
+
+## Installation
+
+ $ npm install password-generator
+
+## Usage
+
+ var generatePassword = require('password-generator');
+
+Default settings (memorable 10 letters)
+
+ generatePassword() // -> xexeyimahi
+
+Custom length not memorable
+
+ generatePassword(12, false) // -> 76PAGEaq6i5c
+
+Characters should match a pattern
+
+ generatePassword(12, false, /\d/) // -> 252667390298
+
+Customize the password prefix
+
+ generatePassword(12, false, /\d/, 'foo-') // -> foo-67390298
+
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2011 Bermi Ferrer <bermi@bermilabs.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1 @@
+module.exports = require('./lib/password-generator');
@@ -0,0 +1,49 @@
+/*!
+ * password-generator
+ * Copyright(c) 2011 Bermi Ferrer <bermi@bermilabs.com>
+ * MIT Licensed
+ */
+
+var 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;
+ }
+ }
+ 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.0.1';
@@ -0,0 +1,9 @@
+{
+ "name": "password-generator"
+ , "version": "0.0.1"
+ , "description": "Memorable password generator"
+ , "keywords": ["password", "generator", "pass", "random"]
+ , "author": "Bermi Ferrer <bermi@bermilabs.com>"
+ , "dependencies": {}
+ , "main": "index"
+}
@@ -0,0 +1,30 @@
+
+/**
+ * Module dependencies.
+ */
+
+var assert = require('assert'),
+ generatePassword = require('../');
+
+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}$/));
+ }
+};
+

0 comments on commit b25cab2

Please sign in to comment.