-
Notifications
You must be signed in to change notification settings - Fork 598
/
utils.py
83 lines (64 loc) · 2.39 KB
/
utils.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from pritunl import settings
import base64
import hashlib
import os
def hash_password_v0(salt, password):
pass_hash = hashlib.sha512()
pass_hash.update(password[:settings.app.password_len_limit].encode())
pass_hash.update(base64.b64decode(salt))
return pass_hash.digest()
def hash_password_v1(salt, password):
pass_hash = hashlib.sha512()
pass_hash.update(password[:settings.app.password_len_limit].encode())
pass_hash.update(base64.b64decode(salt))
hash_digest = pass_hash.digest()
for i in range(5):
pass_hash = hashlib.sha512()
pass_hash.update(hash_digest)
hash_digest = pass_hash.digest()
return hash_digest
def hash_password_v2(salt, password):
pass_hash = hashlib.sha512()
pass_hash.update(password[:settings.app.password_len_limit].encode())
pass_hash.update(base64.b64decode(salt))
hash_digest = pass_hash.digest()
for _ in range(10):
pass_hash = hashlib.sha512()
pass_hash.update(hash_digest)
hash_digest = pass_hash.digest()
return hash_digest
def hash_password_v3(salt, password):
pass_hash = hashlib.sha512()
pass_hash.update(password[:settings.app.password_len_limit].encode())
pass_hash.update(base64.b64decode(salt))
hash_digest = pass_hash.digest()
for _ in range(100000):
pass_hash = hashlib.sha512()
pass_hash.update(hash_digest)
hash_digest = pass_hash.digest()
return hash_digest
def hash_pin_v1(salt, pin):
pass_hash = hashlib.sha512()
pass_hash.update(pin[:settings.app.password_len_limit].encode())
pass_hash.update(base64.b64decode(salt))
hash_digest = pass_hash.digest()
for _ in range(1024):
pass_hash = hashlib.sha512()
pass_hash.update(hash_digest)
hash_digest = pass_hash.digest()
return hash_digest
def hash_pin_v2(salt, pin):
pass_hash = hashlib.sha512()
pass_hash.update(pin[:settings.app.password_len_limit].encode())
pass_hash.update(base64.b64decode(salt))
hash_digest = pass_hash.digest()
for _ in range(100000):
pass_hash = hashlib.sha512()
pass_hash.update(hash_digest)
hash_digest = pass_hash.digest()
return hash_digest
def generate_hash_pin_v2(pin):
salt = base64.b64encode(os.urandom(8)).decode()
pin_hash = base64.b64encode(hash_pin_v2(salt, pin)).decode()
pin_hash = '2$%s$%s' % (salt, pin_hash)
return pin_hash