RndPhrase.js is a library to generate passwords deterministically based on domain context.
Passwords are generated deterministically by computing a hash on a set of credentials (seed, password, domain), using this hash as a pseudo random number generator in order to pick out characters from a predefined alphabet of characters of which the final password (or RndPhrase) is computed.
Import RndPhrase.js as a module in your source.
var RndPhrase = require('rndphrase.js');
Instantiate the object with the minimum configuration requirements
var r = new RndPhrase();
Invoke the generatePassword method
r.generatePassword(function(password) {
console.log(password);
});
// &i#`hVeOIG<$_d0)nZ(FMh*v{LMTv)nL#`9X utL 0
Configuration items are passed as a plain javascript object. Available configuration options:
The seed used. Expected to be a string, but can be everything that can be hashed by the hashing algorithm. Should be entered manually once and saved by the plugin using the library. Remember not to save in plaintext. ;)
A string specifying the location, should be generated automatically by the plugin using the library.
The password entered by the user. Should be entered manually, do not save this anywhere.
Specify how many bits the pseudo random number generator will output to generate a password. The final password is usually almost as large.
Defaults to 42.
Generates a new password with the same credentials.
Defaults to 1.
A constraint is a javascript object with dict with this structure:
{
'min': non-negative-int,
'max': non-negative-int,
'alphabet': string
}
When max < min
, max
is ignored. When max
is 0
it is disabled.
There are four default constraints (or character types): capital
,
minuscule
, numeric
, and special
. Each of which can be deactivated
by setting the constraint to false
. E.g.
var r = new RndPhrase({'capital': false });
The default constraints will be loaded into a constraints
variable
upon initialisation. Active constraints (keys that are not false
)
in this variable will be used on every call to generatePassword()
.
It is possible to add new character types, this is done by configuring
constraints
directly when instantiating the RndPhrase object.
When constraints
is used as a configuration parameter one must
declare all constraints manually. The default constraints object
looks like this:
{
capital: {
min: 1,
max: 0,
alphabet: 'ABCDEFGHIJKLMONPQRSTUVWXYZ'
},
minuscule: {
min: 1,
max: 0,
alphabet: 'abcdefghijklmnopqrstuvwxyz'
},
numeric: {
min: 1,
max: 0,
alphabet: '1234567890'
},
special: {
min: 1,
max: 0,
alphabet: ' !"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
}
}
Overwrite this function to supply another hashing algorithm than
the default (PBKDF2). dprngFunction
takes five arguments password
,
salt
, rounds
, size
, callback
.
The raw password.
The salt is a concatenation of the master seed, the uri and a pepper (to ensure minmal entropy).
How many iterations of the hash to perform. Number is multiplied with 100 and added with 50.000.
The size of the array of numbers to call callback
with
This is an anonymous function which takes a single argument (a byte array) and invokes the internal password generation function.
Overwrite the normal password validation function which checks
whether constraints are upheld. It takes two arguments h
, constraints
The password candidate.
An object containing the defined constraints.
Any questions? Please ask them in #rndphrase on irc.freenode.net.
MIT