-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash_maker.py
More file actions
29 lines (21 loc) · 842 Bytes
/
hash_maker.py
File metadata and controls
29 lines (21 loc) · 842 Bytes
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
from hashlib import sha256
import random
#from secret import get_secret_key
SECRET_KEY = '1231231230'
def make_password(plaintext, app_name):
salt = get_hexdigest(SECRET_KEY, app_name)[:20]
hsh = get_hexdigest(salt, plaintext)
return ''.join((salt, hsh))
def get_hexdigest(salt, plaintext):
return sha256((salt + plaintext).encode('utf-8')).hexdigest()
def password(plaintext, app_name, length):
raw_hex = make_password(plaintext, app_name)
ALPHABET = ('abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTYVWXYZ', '0123456789', '(,._-*~"<>/|!@#$%^&)+=')
num = int(raw_hex, 16)
chars = []
while len(chars) < length:
n = random.randint(0, len(ALPHABET)-1)
alpha = ALPHABET[n]
n = random.randint(0, len(alpha)-1)
chars.append(alpha[n])
return ''.join(chars)