-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassHash.py
41 lines (29 loc) · 1.34 KB
/
passHash.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
import csv
import hashlib
import os
import random
import sys
def hash_file(valid_accs):
# Hashes each user's password Only run once to properly hash passwords already in users.csv from program
# development (see hidden.txt), not including newly-added accounts by user
for user in valid_accs.keys():
newHash = hashlib.sha512((valid_accs[user][1]).encode()).hexdigest()
valid_accs[user][1] = newHash
acc_file_update(valid_accs)
def hash_pass(user_pass, user_salt):
# Hashes a single password (used to create new passwords or change existing passwords)
unencrypted = user_salt + user_pass
newHash = hashlib.sha512(unencrypted.encode()).hexdigest()
return newHash
def acc_file_update(valid_accs):
# Re-writes all of users.csv with most recent list stored in valid_accs_csv
valid_accs_csv = []
for user in valid_accs:
valid_accs_csv.append([user, valid_accs[user][0], valid_accs[user][1], valid_accs[user][2]])
valid_accs_csv.sort()
# Updates users.csv with the hashed passwords so they are not stored in plain text
with open(os.path.join(sys.path[0], "users.csv"), 'w', newline="") as r:
writer = csv.writer(r)
writer.writerows(valid_accs_csv)
def generate_salt():
return ''.join(random.sample('./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 16))