2

I was thinking of writing a little program to generate passwords for me. What I want to do is encrypt the url of the login page with my master password, and take the first ~20 characters as my password for that login page (or however many characters any password length restrictions allow).

What I want to know is, is this secure, even if someone were to find my code (or this question)? By secure, I mean, as secure as the master password itself. For instance, if a site is compromised and an attacker gets one or more of my encryptions + url, can he extract my master password from that? If it's not secure, can I make it secure by adding something?

PS. I realize that this will also screw me if the login page ever changes url, but I can just reset my password then.

  • why would you risk using a master password? why dont you generate individual password for each site you manage then encrypt/hash/salt it. That would be the best practice here, i guess. – rockStar Mar 5 '17 at 16:25
  • Just your final point makes me feel like this solution is really inconvenient (I feel like those URLs change often). Is this meant to replace something like a password manager? – MiaoHatola Mar 5 '17 at 17:12
  • @rockStar I see your point. In fact, I'm trying to generate individual passwords for each site I manage, but I want to do so in a deterministic manner, so that I can do the same regardless of where I am (smartphone, desktop, laptop), without having to resort to hosting an encrypted file in the cloud somewhere, or transferring it between machines all the time. – securityN00b Mar 5 '17 at 21:00
  • @MiaoHatola I don't need to take the entire url, just "stackexchange.com" or "google.com" would work, and I can't see that changing very often. I suppose this would fulfill the same function as a password manager, yes – securityN00b Mar 5 '17 at 21:03
  • @securityN00b Very well. Then Pascal's answer is spot on. – MiaoHatola Mar 5 '17 at 22:15
2

Is this secure, even if someone were to find my code (or this question)? By secure, I mean, as secure as the master password itself.

Yes, this is as secure as your password if you choose your encryption method carefully. In fact, what you want isn't encryption; what you need is a hash function (such as sha256) which takes input and scrambles it to produce a fixed-length output:

hash = sha256(url)

Obviously that's not good enough because there's no master password involved, so you might try

website_password = sha256( password || url)

or

website_password = sha256( url ||  password)

However, even though that might look perfectly fine, don't do it like that!. It's not secure.

What you should do is use a pre-existing primitive, HMAC, which guards against some weaknesses of the above two examples:

website_password = hmac(password, url)

This should be secure (the security depending on the quality of your password and the strength of the hash function used in hmac (you have some room for decisions there - hmac defines a protocol, but gives you a choice in hash primitive).

Still, rockStars's question is valid: Why not just use a password manager and decouple your master password from the site passwords? Because if someone guesses your master password, all your site passwords are immediately known.

  • I wasn't sure if I could use a hash. I thought a hash only guaranteed that it's difficult to find a different input (master password + url) that would result in the same site password. I didn't think it guaranteed anything about being unable to find the original input. Also, about your last comment, isn't the same true for password managers? They require a master password, and if someone guesses it, all my passwords are immediately known, right? – securityN00b Mar 5 '17 at 21:21
  • Re password managers: Yes, but an attacker must also have access to the pw managers database. In your url scheme, all he needs is knowledge about which method you use to arrive at your passwords. – Out of Band Mar 5 '17 at 21:37
  • Re hash: hash functions are one way: You can't determine the original from the scrambled output, just like you can't unscramble an egg to get back what you started with. To get at the original, you have to try out every input and see if it results in the scrambled output (eg your site password). – Out of Band Mar 5 '17 at 21:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.