commit 3cc60e85a98d9dffb8ae0c35fd0386338f86e398
Author: nolash <dev@holbrook.no>
Date: Fri, 26 Jul 2019 21:53:01 +0200
initial commit
Diffstat:
A | pass.py | | | 57 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 57 insertions(+), 0 deletions(-)
diff --git a/pass.py b/pass.py
@@ -0,0 +1,57 @@
+#!/usr/bin/python3
+
+import scrypt
+import argparse
+import getpass
+
+scrypt_salt = b"passwordpractice"
+scrypt_n = 1 << 14
+scrypt_r = 8
+scrypt_p = 1
+scrypt_l = 64
+
+p = argparse.ArgumentParser()
+p.add_argument("-a", action='store_true')
+p.add_argument("pas", nargs='?')
+p.add_argument("description", nargs=argparse.REMAINDER)
+a = p.parse_args()
+
+def hshpwd(s):
+ return scrypt.hash(s, scrypt_salt, scrypt_n, scrypt_r, scrypt_p, scrypt_l)
+
+if (a.a):
+ print("add")
+ if (a.pas == None):
+ print("need password to hash")
+ exit(1)
+ hsh = hshpwd(a.pas)
+ dsc = bytearray(" ".join(a.description), "utf-8")
+ f = open("pass.dat", "ab")
+ f.write(dsc)
+ f.write(b"\x0a")
+ f.write(hsh)
+ f.close()
+ exit(0)
+
+f = open("pass.dat", "rb")
+
+trials = 0
+successes = 0
+while True:
+ nam = f.readline()
+ if len(nam) == 0:
+ break
+ trials += 1
+ hshcorrect = f.read(64)
+ print(nam[:len(nam)-1].decode("utf-8"))
+ suggest = getpass.getpass("> ")
+ hshsuggest = hshpwd(suggest)
+ if hshcorrect != hshsuggest:
+ print("wrong!\n")
+ else:
+ successes += 1
+ print("correct\n")
+
+print("{}/{} ok".format(successes, trials))
+
+f.close()