Last active
February 13, 2024 13:47
-
-
Save DarkblooM-IO/0034a1ee1c963215d3fa7cf39c928c80 to your computer and use it in GitHub Desktop.
genpass: A CLI random password generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import argparse, string, secrets, pyperclip # pyperclip>=1.8.2 | |
parser = argparse.ArgumentParser(prog="genpass", description="A CLI random password generator") | |
parser.add_argument("-l", "--length", help="password length", type=int) | |
parser.add_argument("-a", "--amount", help="number of passwords to generate", type=int) | |
parser.add_argument("-c", "--copy", help="copy password to clipboard", action="store_true") | |
parser.add_argument("-e", "--exclude", help="characters to exclude from password") | |
args = parser.parse_args() | |
length = args.length if args.length else 16 | |
amount = args.amount if args.amount else 1 | |
copy = args.copy | |
exclude = args.exclude | |
characters = list(string.ascii_letters + string.digits + string.punctuation) | |
def main() -> None: | |
if exclude: | |
for c in list(exclude): | |
characters.remove(c) | |
password = "\n".join("".join(secrets.choice(characters) for _ in range(length)) for _ in range(amount)) | |
match copy: | |
case True: | |
pyperclip.copy(password) | |
print("Password copied to clipboard") | |
case False: | |
print(password) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment