Skip to content

Instantly share code, notes, and snippets.

@gronke
Last active November 22, 2023 23:34
Show Gist options
  • Save gronke/33b2ce85001ee706a55f6721f226c3e7 to your computer and use it in GitHub Desktop.
Save gronke/33b2ce85001ee706a55f6721f226c3e7 to your computer and use it in GitHub Desktop.
Generate SHA512-CRYPT with Python 3
#!/usr/bin/env python3
import os
import secrets
import passlib.hash
import sys
def generateHash(password, salt_len=10, iterations=65000):
result = passlib.hash.sha512_crypt(salt=secrets.token_hex(salt_len), rounds=iterations).hash(password)
return '{SHA512-CRYPT}' + result
user_input = sys.argv[1]
print(generateHash(user_input))
@tierpod
Copy link

tierpod commented Jul 23, 2020

Hello, thank you for a good example. But you should use sha512_crypt.using() function if you want to change iterations number

passlib.hash.sha512_crypt.using(salt=secrets.token_hex(salt_len), rounds=iterations).hash(password)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment