-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathzerostore.py
55 lines (39 loc) · 1.45 KB
/
zerostore.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import argparse
import base64
import getpass
import hashlib
import hmac
import math
import pyperclip
import scrypt
import sys
import time
def gen_password(master_pw, user_id, n):
hmac_key = scrypt.hash(master_pw, 'zerostore-salt'+user_id, N=16384, r=8, p=1, buflen=64)
digest = hmac.HMAC(hmac_key, user_id, hashlib.sha256).digest()
return base64.b64encode(digest)[:n]
def main():
parser = argparse.ArgumentParser(description='Generate secure, unique passwords based on a master password.')
parser.add_argument('-c', '--confirm', dest='confirm', default=False, action='store_true',
help='Require a confirmation of the master password.')
parser.add_argument('-n', '--len', dest='n', default=24, type=int,
help='The length of the password to generate. Defaults to 24, maximum 44')
args = parser.parse_args()
if args.n > 44:
print 'Sorry, passwords with a length greater than 32 are not currently supported.'
sys.exit(1)
user_id = raw_input('account id: ')
master_pw = getpass.getpass('password: ')
if args.confirm:
confirm_pw = getpass.getpass('confirm: ')
if confirm_pw != master_pw:
print 'Confirm failed.'
sys.exit(1)
pw = gen_password(master_pw, user_id, args.n)
pyperclip.copy(pw)
print 'Password copied to clipboard'
time.sleep(10)
pyperclip.copy('[cleared]')
print 'Clipboard cleared'
if __name__ == '__main__':
main()