waldyrious / hash-my-pass

A bookmarklet to generate unique passwords per website, based on a single master password.
http://waldyrious.github.io/hash-my-pass/bookmarklet.min.html
Other
17 stars 4 forks source link

Insert more than one digit #19

Open waldyrious opened 9 years ago

waldyrious commented 9 years ago

Some sites require more than one digit, e.g. https://www.netemprego.gov.pt

The code should be something like:

var digits = p.charCodeAt(0);
var posNum = digits % p.length - (digits.toString().length - 1);
if (p.match(/\d/g).length < 2) { // if password doesn't contain at least two digits 
  p = p.replaceAt(posNum, digits);
}

This is basically what's already used to insert a single digit, but without the mod 10 to reduce the digits string (currently called "seed") to a single digit, and using its length (charcodes of base64 strings are the decimal codes of 0-9, A-Z, a-z, and the latter goes into 3 digits near z) in the posNum calculation.

This should already work, but the symbol insertion code would need to be adapted to ensure it doesn't overwrite the inserted digits.