diff --git a/CHANGES.md b/CHANGES.md index e69de29..723665b 100755 --- a/CHANGES.md +++ b/CHANGES.md @@ -0,0 +1,5 @@ +### 0.2.0 ### +* Added: Password type **internet** + +### 0.1.0 ### +Initial Public Release \ No newline at end of file diff --git a/README.md b/README.md index 76281e1..537acff 100755 --- a/README.md +++ b/README.md @@ -15,12 +15,15 @@ Features * Generate Random User Passwords * Random Number Sequences of arbitrary length * Random Pin Numbers (4 Digits) -* Remarkable Human Passwords +* Remarkable Human Passwords (nato+greek alphabet) +* Human passwords/tokens only uses easy readable chars (`l` and `i` are avoided) API ------------------------------ * [numbers](#numbers) - Random Number Sequences of arbitrary length + * [pin](#pin) - Creates a 4 digit numerical code + * [internet](#internet) - Strong passphrases especially used for web services/accounts numbers ------------------------------ @@ -29,6 +32,8 @@ numbers **Syntax:** `sequence:string = numbers([length:int = 8])` +**Output:** `9071248216498` + **Arguments:** * length:int - length of the generated sequence @@ -43,6 +48,38 @@ for (let i=0;i<10;i++){ } ``` +pin +------------------------------ + +**Description:** Creates a 4 digit numerical code + +**Syntax:** `sequence:string = pin()` + +**Output:** `0981` + +internet +------------------------------ + +**Description:** Strong passphrases especially used for web services/accounts + +**Syntax:** `sequence:string = internet([length:int = 22], [shuffle:boolean = false])` + +**Output:** `brGK98]~hkhyNE79_?297` + +**Arguments:** + + * length:int - length of the generated sequence + * shuffle:boolean - flag to enable character position shuffle (random positions) + +**Example:** + +```js +const pw1 = _pwMagic.internet(); +// brGK98]~hkhyNE79_?297 + +const pw2 = _pwMagic.internet(50, true); +// 62p6u4dS934HssJ9*8BMa!(NN}q}384Udoc2F!)8%ยง5!D7psYL +``` Any Questions ? Report a Bug ? Enhancements ? --------------------------------------------- diff --git a/TODO.md b/TODO.md new file mode 100755 index 0000000..d7852e3 --- /dev/null +++ b/TODO.md @@ -0,0 +1 @@ +* Add Random Number generator based on crypto API \ No newline at end of file diff --git a/example.js b/example.js index df7b3c7..429a195 100755 --- a/example.js +++ b/example.js @@ -9,11 +9,17 @@ for (let i=0;i<10;i++){ // 10 numbers console.log('Random Numbers') for (let i=0;i<10;i++){ - console.log('Pin', _pwMagic.numbers(20)); + console.log('Numbers', _pwMagic.numbers(20)); } -// 10 numbers +// 10 passwords console.log('Random Human Passwords (Short)') for (let i=0;i<10;i++){ - console.log('Pin', _pwMagic.humanShort()); + console.log('Human', _pwMagic.humanShort()); +} + +// 10 passwords +console.log('Random Internet Passwords (custom length, shuffled)') +for (let i=0;i<10;i++){ + console.log('Internet', _pwMagic.internet(50, true)); } \ No newline at end of file diff --git a/lib/character-classes.js b/lib/character-classes.js index b691848..db60919 100755 --- a/lib/character-classes.js +++ b/lib/character-classes.js @@ -3,6 +3,7 @@ const cc_special = ['#', '.', ':', ',', ';', '-', '_', '+', '~', '*', '?', '}', const cc_numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; const cc_general_uc = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; const cc_general_lc = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']; +const cc_chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']; const cc_nato = ['ALFA','BRAVO','CHARLIE','DELTA','ECHO','FOXTROT','GOLF','HOTEL','INDIA','JULIETT','KILO','LIMA','MIKE','NOVEMBER','OSCAR','PAPA','QUEBEC','ROMEO','SIERRA','TANGO','UNIFORM','VICTOR','WHISKEY','XRAY','YANKEE','ZULU']; const cc_numberstext = ['ZERO', 'ONE', 'TWO', 'THREE', 'FOUR', 'FIVE', 'SIX', 'SEVEN', 'EIGHT', 'NINE']; const cc_greek = ['ALPHA', 'BETA', 'GAMMA', 'DELTA', 'EPSILON', 'ZETA', 'ETA', 'THETA', 'IOTA', 'KAPPA', 'LAMBDA', 'MU', 'NU', 'XI', 'OMICRON', 'PI', 'RHO', 'SIGMA', 'TAU', 'UPSILON', 'PHI', 'CHI', 'PSI', 'OMEGA']; @@ -22,5 +23,6 @@ module.exports = { greek: cc_greek, general: cc_general, all: cc_all, - words: cc_words + words: cc_words, + chars: cc_chars }; \ No newline at end of file diff --git a/lib/shuffle.js b/lib/shuffle.js new file mode 100755 index 0000000..b469b16 --- /dev/null +++ b/lib/shuffle.js @@ -0,0 +1,19 @@ +const _random = require('./random'); + +// https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle +function shuffle(input){ + + for (let i=input.length-1;i>0;i--){ + const j = _random.randomIntInRange(0, i); + + // exchange elements + const t = input[j]; + input[j] = input[i]; + input[i] = t; + } + + return input; +} + + +module.exports = shuffle; \ No newline at end of file diff --git a/lib/types/internet.js b/lib/types/internet.js new file mode 100755 index 0000000..64fce33 --- /dev/null +++ b/lib/types/internet.js @@ -0,0 +1,45 @@ +const _random = require('../random'); +const _cc = require('../character-classes'); +const _shuffle = require('../shuffle'); + +// alias +const _ = _random.getRandomElementsByClass; + +function createBasicScheme(){ + return '' + + _(_cc.general, 4) + + _(_cc.numbers, 2) + + _(_cc.special, 2) + + _(_cc.general, 6) + + _(_cc.numbers, 2) + + _(_cc.special, 2) + + _(_cc.numbers, 3) + ; +} + +function internet(length, shuffle){ + // defaults + length = length || 22; + shuffle = shuffle || false; + + // tmp + let output = ''; + + // generate passphrase + while (output.length < length){ + output += createBasicScheme(); + } + + // limit length + output = output.substr(0, length); + + // shuffle elements ? + if (shuffle){ + // to array -> shuffle -> to string + output = _shuffle(output.split('')).join(''); + } + + return output; +} + +module.exports = internet; diff --git a/package.json b/package.json index 136ee6c..a639022 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "password-magic", - "version": "0.1.0", + "version": "0.2.0", "author": "Andi Dittrich (https://andidittrich.de)", "license": "MIT", "homepage": "https://github.com/AndiDittrich/Node.password-magic", diff --git a/password-magic.js b/password-magic.js index 95b3334..96ee866 100755 --- a/password-magic.js +++ b/password-magic.js @@ -4,5 +4,6 @@ const _api = {}; _api.pin = require('./lib/types/pin'); _api.numbers = require('./lib/types/numbers'); _api.humanShort = require('./lib/types/human-short'); +_api.internet = require('./lib/types/internet'); module.exports = _api; \ No newline at end of file