Added basic authentication support

This commit is contained in:
jdoe0 2013-08-02 00:07:49 +07:00
parent 7dcde6ac7a
commit 654240abca

View File

@ -3,6 +3,9 @@ from webob.dec import wsgify
from webob.exc import * from webob.exc import *
from webob import Response from webob import Response
import sqlite3
import hashlib
import AnkiServer import AnkiServer
import anki import anki
@ -116,8 +119,24 @@ class SyncApp(object):
Override this to change how users are authenticated. Override this to change how users are authenticated.
""" """
# TODO: This should have the exact opposite default ;-) conn = sqlite3.connect("auth.db")
return True cursor = conn.cursor()
param = (username,)
cursor.execute("SELECT hash FROM auth WHERE user=?", param)
db_ret = cursor.fetchone()
if db_ret != None:
db_hash = str(db_ret[0])
salt = db_hash[-16:]
hashobj = hashlib.sha256()
hashobj.update(username+password+salt)
return (db_ret != None and hashobj.hexdigest()+salt == db_hash)
def username2dirname(self, username): def username2dirname(self, username):
""" """