Skip to content

Instantly share code, notes, and snippets.

@ryot4
Last active September 25, 2022 06:19
Show Gist options
  • Save ryot4/871813a4af8f84f618496ff6b3993336 to your computer and use it in GitHub Desktop.
Save ryot4/871813a4af8f84f618496ff6b3993336 to your computer and use it in GitHub Desktop.
Hash passwords
#!/usr/bin/env python3
import argparse
import crypt
from crypt import METHOD_SHA256, METHOD_SHA512, METHOD_BLOWFISH, crypt, mksalt
from getpass import getpass
parser = argparse.ArgumentParser(description='Hash passwords')
parser.add_argument('-5',
action='store_const',
const=METHOD_SHA256,
dest='method',
help='Use SHA-256 algorithm')
parser.add_argument('-6',
action='store_const',
const=METHOD_SHA512,
dest='method',
help='Use SHA-512 algorithm')
parser.add_argument('-bcrypt',
action='store_const',
const=METHOD_BLOWFISH,
dest='method',
help='Use Blowfish algorithm')
args = parser.parse_args(namespace=argparse.Namespace(method=METHOD_SHA256))
print(crypt(getpass(), mksalt(args.method)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment