Skip to content

Instantly share code, notes, and snippets.

@meineerde
Created November 24, 2014 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meineerde/1ed655dca31fd904fbf7 to your computer and use it in GitHub Desktop.
Save meineerde/1ed655dca31fd904fbf7 to your computer and use it in GitHub Desktop.
mkpasswd in python
#!/usr/bin/env python
# Generate a new SHA512 shadow password hash from a given password
# Based on https://github.com/antoncohen/mksha
import getpass
import sys
# To install this library, use one of these:
# pip install passlib
# easy_install passlib
from passlib.hash import sha512_crypt
if __name__ == "__main__":
passwd = getpass.getpass('Password to hash: ')
passwd_repeat = getpass.getpass('Repeat: ')
if (passwd != passwd_repeat):
print "Passwords don't match!"
sys.exit(1)
hash = sha512_crypt.encrypt(passwd)
print hash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment