Skip to content

Instantly share code, notes, and snippets.

@JayBeavers
Created April 26, 2020 02:08
Show Gist options
  • Save JayBeavers/7bca0642f591daab0d0916dbcdd4e3b3 to your computer and use it in GitHub Desktop.
Save JayBeavers/7bca0642f591daab0d0916dbcdd4e3b3 to your computer and use it in GitHub Desktop.

Revisions

  1. JayBeavers created this gist Apr 26, 2020.
    28 changes: 28 additions & 0 deletions SSHA512_gen.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #!/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.encode('utf-8'))
    sha.update(salt)
    ssha512 = base64.b64encode('{}{}'.format(sha.digest(), salt).encode('utf-8'))

    # Print it out with a prefix for Dovecot
    print("\n{{SSHA512}}{}".format(ssha512))