pass.py (1094B)
1 #!/usr/bin/python3 2 3 import scrypt 4 import argparse 5 import getpass 6 7 scrypt_salt = b"passwordpractice" 8 scrypt_n = 1 << 14 9 scrypt_r = 8 10 scrypt_p = 1 11 scrypt_l = 64 12 13 p = argparse.ArgumentParser() 14 p.add_argument("-a", action='store_true') 15 p.add_argument("pas", nargs='?') 16 p.add_argument("description", nargs=argparse.REMAINDER) 17 a = p.parse_args() 18 19 def hshpwd(s): 20 return scrypt.hash(s, scrypt_salt, scrypt_n, scrypt_r, scrypt_p, scrypt_l) 21 22 if (a.a): 23 print("add") 24 if (a.pas == None): 25 print("need password to hash") 26 exit(1) 27 hsh = hshpwd(a.pas) 28 dsc = bytearray(" ".join(a.description), "utf-8") 29 f = open("pass.dat", "ab") 30 f.write(dsc) 31 f.write(b"\x0a") 32 f.write(hsh) 33 f.close() 34 exit(0) 35 36 f = open("pass.dat", "rb") 37 38 trials = 0 39 successes = 0 40 while True: 41 nam = f.readline() 42 if len(nam) == 0: 43 break 44 trials += 1 45 hshcorrect = f.read(64) 46 print(nam[:len(nam)-1].decode("utf-8")) 47 suggest = getpass.getpass("> ") 48 hshsuggest = hshpwd(suggest) 49 if hshcorrect != hshsuggest: 50 print("wrong!\n") 51 else: 52 successes += 1 53 print("correct\n") 54 55 print("{}/{} ok".format(successes, trials)) 56 57 f.close()