Skip to content

Commit

Permalink
added password type internet
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiDittrich committed Oct 6, 2017
1 parent 45592d6 commit 7ebc7cd
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### 0.2.0 ###
* Added: Password type **internet**

### 0.1.0 ###
Initial Public Release
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------------------
Expand All @@ -29,6 +32,8 @@ numbers

**Syntax:** `sequence:string = numbers([length:int = 8])`

**Output:** `9071248216498`

**Arguments:**

* length:int - length of the generated sequence
Expand All @@ -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 ?
---------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Add Random Number generator based on crypto API
12 changes: 9 additions & 3 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
4 changes: 3 additions & 1 deletion lib/character-classes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -22,5 +23,6 @@ module.exports = {
greek: cc_greek,
general: cc_general,
all: cc_all,
words: cc_words
words: cc_words,
chars: cc_chars
};
19 changes: 19 additions & 0 deletions lib/shuffle.js
Original file line number Diff line number Diff line change
@@ -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;
45 changes: 45 additions & 0 deletions lib/types/internet.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions password-magic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 7ebc7cd

Please sign in to comment.