not store tokens, just the hashes

This commit is contained in:
Ville Rantanen
2018-12-05 12:59:00 +02:00
parent a12b9e9462
commit 74cdb27037
2 changed files with 7 additions and 6 deletions

View File

@@ -5,6 +5,7 @@ import os
from werkzeug.utils import secure_filename
import html
import sqlite3
import hashlib
def connect_db():
return sqlite3.connect(app.config['DATABASE'])
@@ -32,7 +33,8 @@ def create_db(db_file):
)
db.commit()
def get_hash(s):
return hashlib.sha224(s.encode('utf-8')).hexdigest()
def get_token_counts(db, key):
cur = db.cursor()
@@ -92,7 +94,7 @@ def has_voted(key, token):
cur.execute(
"SELECT token FROM tokens WHERE token = ? AND answered = 'true' AND question_set = ?",
(
token,
get_hash(token),
key
)
)
@@ -245,7 +247,7 @@ def write_vote(key, token, answers, form):
cur.execute(
"UPDATE tokens SET answered = 'true' WHERE token = ? AND question_set = ?",
(
token,
get_hash(token),
key
)
)