Skip to content

Instantly share code, notes, and snippets.

@naftulikay
Last active December 10, 2021 16:46
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 naftulikay/e7a6ef31fd7d1dce3fcfd252fb435a2f to your computer and use it in GitHub Desktop.
Save naftulikay/e7a6ef31fd7d1dce3fcfd252fb435a2f to your computer and use it in GitHub Desktop.
Generate an /etc/shadow compatible passphrase.
#!/usr/bin/env python3
from crypt import crypt
from getpass import getpass
from random import SystemRandom ; random = SystemRandom()
from string import ascii_lowercase, ascii_uppercase, digits
salt_chars = ascii_lowercase + ascii_uppercase + digits
# generate a SHA-512 passphrase from user input with a 16 byte random salt
passphrase = crypt(getpass(), "$6${}".format(''.join([random.choice(salt_chars) for i in range(16)])))
# print the output
print(passphrase)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment