# Which algorithm do you recommend for practical use to generate unique passwords for each website?

So, in my imagination there is this simple algorithm with only one master password, let's say a prime number 'p', which I have to remember. Using only the address of the website and p, the algorithm must generate a unique password. It must be at least almost impossible to guess the value of p even if you know the algorithm. Also impossible to guess the password of website B if you know the password of website A and the algorithm. The reason why I need this algorithm: I'd have different passwords and would have to remember only one number. There's also the matter of having multiple accounts on the same website but I think it will be easy to modify the algorithm. I think it will be useful for many users.

• Use a password manager to randomly generate your passwords and store them. Jul 23, 2014 at 13:51
• You should also consider password compromise (not the master secret, but individual passwords that you need to change for whatever reason). You could append a counter, or some other information that can be easily remembered and updated infrequently, if you don't want to store them, which I imagine is the whole point of the idea. Jul 23, 2014 at 14:19

The problem is almost exactly the same as in password based key derivation, so you could use a similar solution.

1. Derive a master secret from your password and a unique salt using e.g. PBKDF2 or scrypt: $S_m = PBKDF(p, s)$.
2. Derive a site-specific secret from the master using e.g. HKDF and the site URL: $S_u = HKDF(S_m, u)$.
3. Turn the site secret into a usable password, e.g. by encoding in base 64.

If you go this route you are putting all your eggs in one basket. If you forget the master password, you lose all the derived ones. If someone guesses it, they can derive all the others.

You would probably be better off just using a password manager that prevents guessing attacks. Otherwise the master must be very strong. A password manager generates random site passwords that leak no information about the master.

• "If you go this route you are putting all your eggs in one basket. If you forget the master password, you lose all the derived ones. If someone guesses it, they can derive all the others." How is this any different than a password manager exactly? Or do you mean one of those online ones? And, yes, the master password must have quite a lot of entropy if you do this, at least 60 to 80 bits. Jul 23, 2014 at 14:21
• @Thomas, some password managers allow you to create a recovery key that uses another password. Others, like 1password, allow you to store a backup of the database using another master password.
– otus
Jul 23, 2014 at 14:30
• Many sites have password requirements than make the "Turn the site secret into a usable password" step non-trivial, and hard to get right; like (I'm not making that up): At least 15 characters. Contains CAPITAL Letters. Contains SMALL letters. Contains either special characters or numbers (e.g. / , *, @, #, $, or 1, 2, 3 etc.).$\;\$ Typically that spec is imprecise, often hard to get or/and existing in different versions, and more often than not wrong (e.g. here, the system actually allows both special characters and numbers, and I'm not even sure that it does not require that).
– fgrieu
Jul 23, 2014 at 14:32
• @fgrieu, very true. After Heartbleed was fixed I tried changing PayPal password, and their form lies about what's allowed – I had to try almost ten different versions before it passed, removing complexity and characters. In that case you have to have some kind of scheme like: fulfill requirements in simplest possible way (e.g. "aA1.") then add as many characters from the hash as allowed. Yet another reason why a password manager is the better solution.
– otus
Jul 23, 2014 at 19:11