28 lines
857 B
Python
28 lines
857 B
Python
|
#@+leo-ver=4-thin
|
||
|
#@+node:jpenner.20090607135901.1:@thin auth.py
|
||
|
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()
|
||
|
|
||
|
#@-node:jpenner.20090607135901.1:@thin auth.py
|
||
|
#@-leo
|