Skip to content

Instantly share code, notes, and snippets.

@andrewslotin
Created July 10, 2018 15:13
Show Gist options
  • Save andrewslotin/9bb1a55b45c4028d501b2db67c535ab1 to your computer and use it in GitHub Desktop.
Save andrewslotin/9bb1a55b45c4028d501b2db67c535ab1 to your computer and use it in GitHub Desktop.
/etc/shadow compatible password encryption using SHA-512 hash with salt
#!/usr/bin/env python3
import crypt
from getpass import getpass
try:
from passlib.hash import sha512_crypt
except ImportError:
from sys import stderr
stderr.write("please run 'pip3 install passlib' to make sure you have passlib installed\n")
exit(1)
password = getpass()
while getpass("Re-type password: ") != password:
print("\nPasswords don't match, please try again")
password = getpass()
salt = crypt.mksalt(crypt.METHOD_SHA512).split("$")[-1]
print(sha512_crypt.hash(password, salt=salt, rounds=5000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment