Add login upgrade script (only run this once!!)
This commit is contained in:
parent
88ed4006f2
commit
0d5c823e7a
43
DreamTown/upgrade_login.py
Normal file
43
DreamTown/upgrade_login.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user