We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents c179ce9 + aa0530e commit a3d1020Copy full SHA for a3d1020
lwh/21/encrpyt.py
@@ -0,0 +1,24 @@
1
+from hashlib import sha256
2
+from hmac import HMAC
3
+import os
4
+
5
6
+class Encrypt(object):
7
8
+ def encrypt(self, password, salt=None):
9
+ if salt is None:
10
+ salt = os.urandom(8)
11
+ result = password.encode('utf-8')
12
+ for i in range(10):
13
+ result = HMAC(result, salt, sha256).digest()
14
+ return salt + result
15
16
+ def vaildate(self, password, hashed):
17
+ return hashed == self.encrypt(password, salt=hashed[:8])
18
19
+if __name__ == '__main__':
20
+ obj = Encrypt()
21
+ hashed = obj.encrypt('wh5622')
22
+ # print(bytes.decode(hashed))
23
+ ans = obj.vaildate('wh5622', hashed)
24
+ print(ans)
0 commit comments