Skip to content

Instantly share code, notes, and snippets.

@CrazyLionHeart
Forked from garrettreid/SSHA512_gen.py
Last active August 29, 2015 14:11
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 CrazyLionHeart/8a57bd06013a6dcddc55 to your computer and use it in GitHub Desktop.
Save CrazyLionHeart/8a57bd06013a6dcddc55 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import os
import hashlib
import getpass
import base64
password1 = None
password2 = None
# Read the password
while password1 != password2 or password1 == None:
password1 = getpass.getpass()
password2 = getpass.getpass("Confirm password: ")
if (password1 != password2):
print "\nPassword mismatch, try again."
# Generate a 5 byte random salt
salt = os.urandom(5)
# Hash our password + salt
sha = hashlib.sha512()
sha.update(password1)
sha.update(salt)
ssha512 = base64.b64encode('{}{}'.format(sha.digest(), salt))
# Print it out with a prefix for Dovecot
print "\n{{SSHA512}}{}".format(ssha512)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment