Skip to content

Instantly share code, notes, and snippets.

@kfiresmith
Last active October 31, 2023 16:28
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 kfiresmith/f1467580096a05fcdb9eaeab285fbc5e to your computer and use it in GitHub Desktop.
Save kfiresmith/f1467580096a05fcdb9eaeab285fbc5e to your computer and use it in GitHub Desktop.
Emit a SHA512 shadow string for /etc/shadow
#!/usr/bin/python
import crypt
import getpass
import re
import sys
sys.dont_write_bytecode = True
while True:
password1 = getpass.getpass(prompt='Enter a password string to hash in SHA-512: ')
password2 = getpass.getpass(prompt='Enter the password again to confirm: ')
if password1 != password2:
print("Passwords do not match. Please try again.")
continue
if len(password1) < 8:
print("Password must be at least 8 characters long.")
continue
if not re.search("[a-z]", password1):
print("Password must contain at least one lowercase letter.")
continue
if not re.search("[A-Z]", password1):
print("Password must contain at least one uppercase letter.")
continue
if not re.search("[0-9]", password1):
print("Password must contain at least one number.")
continue
if not re.search("[!@#$_%^&*(),.?\":{}|<>]", password1):
print("Password must contain at least one symbol.")
continue
break
print(crypt.crypt(password1, crypt.mksalt(crypt.METHOD_SHA512)))
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment