Created
May 20, 2020 00:52
-
-
Save 6d61726b760a/a14b5a61cd56c2ae38e656c8029ca49d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import random | |
import xkcdpass.xkcd_password as xp | |
# generate random passwords | |
# a variation on https://github.com/redacted/XKCD-password-generator/blob/master/examples/example_import.py | |
def random_capitalisation(s, chance): | |
new_str = [] | |
for i, c in enumerate(s): | |
new_str.append(c.upper() if random.random() < chance else c) | |
return "".join(new_str) | |
def random_symbol(): | |
symbol_list = '+-_!@#$%^*?|~' | |
random_symbol = random.choice(symbol_list) | |
return random_symbol | |
def capitalize_first_letter(s): | |
new_str = [] | |
s = s.split(" ") | |
for i, c in enumerate(s): | |
new_str.append(c.capitalize()) | |
return "".join(new_str) | |
words = xp.locate_wordfile('words.txt') | |
for i in range(5): | |
mywords = xp.generate_wordlist(wordfile=words, min_length=5, max_length=8) | |
password = xp.generate_xkcdpassword(mywords,delimiter=random_symbol()) | |
password = random_capitalisation(password, 2/10.0) | |
symbol = random_symbol() | |
number = random.randrange(1000, 10000, 2) | |
print(f"{password}{symbol}{number}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment