Skip to content

Instantly share code, notes, and snippets.

@ilyaevseev
Last active August 8, 2024 18:34
Show Gist options
  • Save ilyaevseev/7592cc899841150bc11669f926234dc7 to your computer and use it in GitHub Desktop.
Save ilyaevseev/7592cc899841150bc11669f926234dc7 to your computer and use it in GitHub Desktop.
Generate bcrypt password for GLAuth
#!/usr/bin/python3
# apt install python3-bcrypt
import string
import random
import bcrypt
import sys
from getpass import getpass
passlen = 30
letters = string.ascii_letters
if len(sys.argv) > 1:
plain = "".join(random.choice(letters) for i in range(passlen))
echop = True
else:
print("Enter password:", end = " ")
plain = getpass()
echop = False
crypted = bcrypt.hashpw(plain.encode("utf-8"), bcrypt.gensalt())
hexcrypt = "".join("{:02x}".format(c) for c in crypted)
print(plain) if echop else print("")
print(crypted.decode("utf-8"))
print(hexcrypt)
## END ##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment