-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo_the_pw_thing.py
38 lines (30 loc) · 1.02 KB
/
do_the_pw_thing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import random
import re
from xkcdpass import xkcd_password as xp
from string import ascii_letters, digits
special_chars = ".,:-_#+*~=?!$%&/<>"
chars = tuple(set(ascii_letters + digits + special_chars))
rand_gen = random.SystemRandom()
def generate_pw(wordfile="ger-anlx,eff-short", random_delimiters=True, numwords=6):
wordfile = wordfile or xp.locate_wordfile()
mywords = xp.generate_wordlist(wordfile=wordfile)
dl = '-'
if random_delimiters:
dl = rand_gen.choice(special_chars)
return xp.generate_xkcdpassword(mywords, delimiter=dl, numwords=numwords)
def ensure_ascii(pw):
replacements = [
('ä', 'ae'),
('ö', 'oe'),
('ü', 'ue'),
('Ä', 'AE'),
('Ö', 'OE'),
('U', 'UE'),
('ß', 'ss'),
('ẞ', 'SS')
]
for i in replacements:
pw = pw.replace(i[0], i[1])
return re.sub('[^{}]+'.format(re.escape(''.join(chars))), '_', pw)
def tmp_pass(length=128):
return u''.join(rand_gen.choice(chars) for dummy in range(length))