marmots/auth.py

23 lines
737 B
Python

import MySQLdb
import hashlib
import config
class NoopAuth(object):
def FAuthorized(self, user, passwd):
return True
class DrupalAuth(object):
def FAuthorized(self, user, passwd):
conn = MySQLdb.connect(host = config.drupaldb_host, user = config.drupaldb_user, passwd = config.drupaldb_password, db = config.drupaldb)
try:
cursor = conn.cursor()
try:
cursor.execute("SELECT name, pass FROM users WHERE name = %s AND pass = %s", (user, hashlib.md5(passwd).hexdigest()))
return cursor.fetchone() != None
finally:
cursor.close()
except Exception:
return False
finally:
conn.close()