-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostq.py
More file actions
56 lines (33 loc) · 1.28 KB
/
postq.py
File metadata and controls
56 lines (33 loc) · 1.28 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import secrets
from quantcrypt.kdf import KKDF
from typing import Optional
class PasswordGenerator:
def __init__(self, master_key: Optional[bytes] = None) -> None:
self.master_key = master_key or secrets.token_bytes(64)
self.charset = "abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789!@#$%^&*"
def generate_password(self, length: int) -> str:
length = max(1, length)
derive_len = max(32, length)
password_bytes = KKDF(
master=self.master_key,
key_len=derive_len,
num_keys=1
)[0] # 1st ele
password_bytes = password_bytes[:length]
password = ''.join(
self.charset[byte % len(self.charset)]
for byte in password_bytes
)
return password
def main():
generator = PasswordGenerator()
for length in [16, 24, 32]:
password = generator.generate_password(length)
print(f"Length {length}: {password}")
def call(l):
generator = PasswordGenerator()
for length in [ l ,16, 24, 32]:
password = generator.generate_password(length)
print(f"Length {length}: {password}")
if __name__ == "__main__":
main()