Skip to content

Instantly share code, notes, and snippets.

@padamupreti
Last active January 12, 2022 15:32
Show Gist options
  • Save padamupreti/0fa15180c32ddef70653abfe801ef708 to your computer and use it in GitHub Desktop.
Save padamupreti/0fa15180c32ddef70653abfe801ef708 to your computer and use it in GitHub Desktop.
strong passphrase generator and copier
# strong passphrase generator and copier
from secrets import choice, randbelow
from string import ascii_lowercase, ascii_uppercase, punctuation, digits
import pyperclip # pip install pyperclip
def choose_specified(group, num=2):
if len(group) == 1:
return group
return ''.join(choice(group) for _ in range(num))
def get_passphrase():
char_groups = [ascii_lowercase, ascii_uppercase, punctuation, digits, ' ']
all_groups_str = ''.join(char_groups)
keyphrase = ''.join(choice(all_groups_str) for _ in range(9))
for _ in range(len(char_groups)):
index = randbelow(len(char_groups))
keyphrase += choose_specified(char_groups[index])
del char_groups[index]
return keyphrase
pyperclip.copy(get_passphrase())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment