Skip to content

Instantly share code, notes, and snippets.

@chernjie
Last active September 15, 2023 07:19
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 chernjie/ceafd6f7bd02cfd77f3738e14c0a9720 to your computer and use it in GitHub Desktop.
Save chernjie/ceafd6f7bd02cfd77f3738e14c0a9720 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from optparse import OptionParser
from passlib.hash import sha512_crypt;
import getpass;
parser = OptionParser(usage="%prog --method=sha-512")
parser.add_option(
'--method',
dest='method', default='',
help='chosen method, e.g. sha-512',
)
(opts, args) = parser.parse_args()
def sha512_crypted (password) :
print(sha512_crypt.using(rounds=5000).hash(password))
methods = {
'sha-512': sha512_crypted,
}
if __name__ == '__main__':
if not opts.method:
parser.error("Please provide a method, e.g. sha-512")
try:
methods[opts.method](getpass.getpass())
except KeyError as ke:
parser.error("Method not supported")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment