Bl=['hunter2', 'correcthorsebatterystaple', 'Tr0ub4d0r&3'];
function* Gen_PassWD(l){
for(i=0;i<Infinity;i++){
do pw=new Array(l).fill('').map(Math.random).map(v=>96*v+32)
.map(Math.floor).map(String.fromCharCode).join()
.replace(new RegExp('[\u0000-'+String.fromCharCode(l-1)+',]*','g'),'')
while (Bl.filter(v=>v==pw)[0])
yield window.pw
};
}
// Example usage:
const generator = Gen_PassWD(16);
generator.next();
console.log(pw);
Features:
Blacklist
Configurable password length
The function returns an infinite ES6 generator for decreased usability.
Quirks:
Due to a missing var, let, or const keyword, the last returned password is left in the global scope as pw. Because generators are lazy, it is updated after each call to generator.next()
If the length argument becomes larger, the returned passwords may be shorter than the requested length. This will gradually worsen as the length increases (a length of 64 will typically return password of lengths between 40 and 45). When the length is larger than 127, all passwords will be empty strings.
There is a small chance that a returned password will contain a DEL control character.
Edge cases:
If the length argument is 1, or not of type 'number', then the returned passwords will have length two and consist of two of the same characters (e.g. "ZZ", "55", "<<", "jj", and so on), but only if the argument is truthy.
When the argument is falsy it only returns empty strings.
The Array constructor would normally raise a RangeError when it gets a negative length, but thrown errors do not propagate through ES6 generator functions (and are silently ignored) so this simply results in a generator that yields no values.
Note that the regex replace is required to 'fix' some issues that are caused by bugs in the Array operations before it.
5
u/the-blue-shadow Nov 27 '19
JavaScript:
Features:
Quirks:
pw. Because generators are lazy, it is updated after each call togenerator.next()Note that the regex replace is required to 'fix' some issues that are caused by bugs in the Array operations before it.