Add login upgrade script (only run this once!!)

This commit is contained in:
Bluzume 2019-12-26 12:26:14 +13:00 committed by GitHub
parent 88ed4006f2
commit 0d5c823e7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 0 deletions

View File

@ -0,0 +1,43 @@
# A script to update login hash to new format (more secure)
import sqlite3
import binascii
import hashlib
SQLLITE_DB_PATH = "DreamTown.db"
db = sqlite3.connect(SQLLITE_DB_PATH)
c = db.cursor()
cur = c.execute("SELECT PassHash FROM users")
rows = cur.fetchall()
for row in rows:
ogPassHash = row[0]
passHashBin = binascii.unhexlify(ogPassHash)
m = hashlib.sha512()
m.update(passHashBin)
PassHash = binascii.hexlify(m.digest()).decode("utf-8")
print("P: "+str(ogPassHash) + " : " + str(PassHash))
c.execute('UPDATE users SET PassHash=? WHERE PassHash=?',(PassHash,ogPassHash))
cur = c.execute("SELECT AnswerHash FROM securityQuestion")
rows = cur.fetchall()
for row in rows:
ogAnswerHash = row[0]
answerHashBin = binascii.unhexlify(ogAnswerHash)
m = hashlib.sha512()
m.update(answerHashBin)
AnswerHash = binascii.hexlify(m.digest()).decode("utf-8")
print("A: "+str(ogAnswerHash) + " : " + str(AnswerHash))
c.execute('UPDATE securityQuestion SET AnswerHash=? WHERE AnswerHash=?',(AnswerHash,ogAnswerHash))
db.commit()
db.close()