Skip to content

Instantly share code, notes, and snippets.

@jaseg
Created August 12, 2012 22:32
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save jaseg/3334991 to your computer and use it in GitHub Desktop.
Save jaseg/3334991 to your computer and use it in GitHub Desktop.
Password manager without a password manager

Prelude

Since password managers are big and complicated and I currently am pretty bored since I am sitting in a car for a few hours, here is a simple algorithm to generate resource-specific, unique passwords using a master password and no password database.

WARNING

As pointed out here: http://news.ycombinator.com/item?id=4374888 this method is broken.

Usage

Simply paste the following line into a shell, type your master password (correctly, please, for there are no safeguards in place to protect you from typos) and press [enter] [ctrl-d] and you will be provided with a secure password specific for www.example.com.

(sha512sum ~/.salt -<<<www.example.com;sha512sum -)|cut -d\  -f1|sha512sum|cut -c-32

Please not that this line will produce the same password every time you invoke it, provided that nobody messed around in your .salt file and you still remember your master password.

The salt can be pretty much any immutable file (i.e. .jpg and other files which tend to be modified by programs because of stored metadata are a really bad idea), as long as it is more or less unique. I generated mine with the following command line:

(dmesg;env;head -c16 /dev/random)|sha512sum>>~/.salt; chmod 400 ~/.salt

Under certain circumstances, this line may take a few seconds while /dev/random gathers entropy.

Principle of operation

The password generate takes hex sha512-hashes of your salt file, your master password and the resource name you wish to generate a password for (i.e. e.g. a domain name), concatenates them one per line, hashes the result and takes the first 32 characters of the result's hex value. The resulting value is dependant on each of the three variables and no one of the variables can be computed from it (these are properties of cryptographic hashes as sha-512 is one). Obviously, the process could be improved if you would find a portable way to encode the resulting hash in a charset consisting of more than 16 digits, for then the resulting password could be made significantly shorter than 32 characters without loosing any entropy compared to now.

The salt file generation takes your dmesg (system-specific), your env (user specific) and a few random bytes (random), concatenates and hashes them, and puts the hash's hex string into the salt file.

@corroded
Copy link

Just a clarification, this produces a 32-character password? Most sites don't accept passwords that long, although 16-char ones are accepted. I like the idea of the length of the pass vs the complexity of its characters. Also, if you're on OSX(I'm pretty sure there's a linux port of this) you can just pipe everything to pbcopy so you automatically have it on your clipboard. Best way would be to create a one-two char alias in your shell, something like op so you can just fire your terminal (i use ctrl + ~), type op example.com (or you can even add aliases to sites: fb for facebook etc) then boom, you got your password on your clipboard. 4 keystrokes + the site name/alias vs your 8-16 char password? I'd take this any day :)

Great idea!

@corroded
Copy link

And look, it's now a gem! Thanks @jroes!

@myano
Copy link

myano commented Aug 13, 2012

I don't see why people would rely on a third party service like LastPass. You are relying on their uptime to access your passwords, when I could use KeePassX and put my .kdb file everywhere I expect to use it. (Yes this may be a bit inconvenient, but the advantage here is if something happens to one of the copies of .kdb (ie it's destroyed or wiped) I have a backup located elsewhere and typically further encrypted past what just the application offers.

As far as generating passwords I think this is a nifty idea, definitely not a bullet proof idea. Then again, no solution is the perfect solution. What works for me might not work for others, and vice versa.

@JensRantil
Copy link

This is a great idea! I like it! Something that concerns me a little is the fact that sha512sum is limited to output characters [0-9][a-e]. This makes a generated password way weaker than it has to if a longer SHA512 sum could be reduced a shorted password with more characters that would be awesome! Could probably be done using an awk script.

@corroded and @MatthewWilkes: Once could possibly create another file that maps webside => password length. This would solve the issue of remembering the length of passwords for different websites.

@bluesmoon
Copy link

hex is restricted to 16 symbols though. better to use a base64 representation of the hash...

ps: it is 4:15am where i am, so...

@andreyvit
Copy link

@myano I guess we're less concerned about temporary unavailability (for which LastPass has a solution which few people use), and more about keeping them in sync across all devices and about the cognitive burden of having to deal with backing them up. And LastPass Premium has benefits like secure sharing.

But yeah, if the salt could be derived from something (like your personal info) so that it can be recovered, and if the master password is remembered by a browser extension, generated passwords could be a very nifty way to deal with the problem.

@dogeared
Copy link

If anyone's interested, I created a chrome plugin that generates high quality passwords conveniently. You put in a long secret phrase which will stay in memory for a configurable amount of time. In the password field of site you wish to log in to, you type a nickname and then hit a key sequence (default is: Ctrl+Option+Command+A) to generate a password using the secret combined with the nickname. Dig it: https://chrome.google.com/webstore/detail/bpkpmidmfbiafdmlbgcnpjpkkafnijgc

@eric-brechemier
Copy link

I created an open-source project using a somewhat similar approach, using different hash algorithms for passwords with different sizes and ranges of characters:
http://enlargeyourpassword.com

GitHub Project:
https://github.com/eric-brechemier/enlargeyourpassword

@Friz-zy
Copy link

Friz-zy commented Nov 4, 2012

Hi, the python version of sha512(sha512("salt" XOR "nick : site") XOR "pass")[:32] algoritm now in https://github.com/Friz-zy/pass_etalon and https://github.com/Friz-zy/passGui

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment