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

@@ -21,7 +21,7 @@ def insert_token(db, name, token):
); );
""", """,
( (
token, get_hash(token),
name name
) )
) )
@@ -41,8 +41,7 @@ def manage_tokens(options):
) )
) )
for row in cur: for row in cur:
print("%s/vote/%s/%s (%s)"%( print("%s:%s (%s)"%(
options.prefix,
options.name, options.name,
row[0], row[0],
"used" if row[1] == "true" else "unused" "used" if row[1] == "true" else "unused"

View File

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