-
Notifications
You must be signed in to change notification settings - Fork 20
/
pass
executable file
·58 lines (47 loc) · 1.63 KB
/
pass
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
56
57
58
#!/bin/env python3
import string
from getpass import getpass
from hashlib import sha512
def_charset = string.ascii_letters + string.digits + string.punctuation
def_length = 32
header = 'PASS - password generator'
print('*'*len(header))
print(header)
print('*'*len(header))
def repeated_input(prompt):
rv = ""
while not rv: rv = input(prompt)
return rv
def repeated_input_hidden(prompt):
rv = ""
while not rv: rv = getpass(prompt=prompt)
return rv
specific_key = repeated_input('enter specific key: ')
generic_key = repeated_input_hidden('enter secret generic key: ')
d_generic_key = repeated_input_hidden('confirm secret generic key: ')
if generic_key != d_generic_key:
print('generic key doesnt match')
exit(1)
charset = input(f'enter allowed character set (default = \'{def_charset}\'): ').strip()
length = input(f'enter length of password (default = {def_length}): ').strip()
length = int(length) if length else def_length
charset = charset if charset else def_charset
if len(charset) > 256:
print('charset cannot be longer than 256 characters, taking first 256 values')
charset = charset[:256]
salted = ( generic_key * len(specific_key) ) + ( specific_key * len(generic_key) )
password = ''
hashobj = sha512(salted.encode())
charset_len = len(charset)
while len(password) < length:
for byte in hashobj.digest():
ind = byte % charset_len
password += charset[ind]
if len(password) > length:
break
hashobj.update(salted.encode())
password = password[:length]
#print(password)
import pyperclip # install pyperclip
pyperclip.copy(password)
print('password copied to clipboard')