2011-03-19 00:10:02 +00:00
|
|
|
import MySQLdb
|
|
|
|
import hashlib
|
|
|
|
import config
|
2020-06-27 16:05:34 +00:00
|
|
|
import bcrypt
|
|
|
|
import traceback
|
2011-03-19 00:10:02 +00:00
|
|
|
|
|
|
|
class NoopAuth(object):
|
|
|
|
def FAuthorized(self, user, passwd):
|
|
|
|
return True
|
|
|
|
|
|
|
|
class DrupalAuth(object):
|
2020-06-27 16:05:34 +00:00
|
|
|
def FHashMatches(self, md5, dbhash):
|
|
|
|
return md5 == dbhash
|
2011-03-19 00:10:02 +00:00
|
|
|
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:
|
2020-06-27 16:05:34 +00:00
|
|
|
firsthash = hashlib.md5(passwd).hexdigest()
|
|
|
|
cursor.execute("SELECT pass FROM users WHERE name = %s", (user,))
|
|
|
|
row = cursor.fetchone()
|
|
|
|
return row and self.FHashMatches(firsthash, row[0])
|
2011-03-19 00:10:02 +00:00
|
|
|
finally:
|
|
|
|
cursor.close()
|
|
|
|
except Exception:
|
2020-06-27 16:05:34 +00:00
|
|
|
traceback.print_exc()
|
2011-03-19 00:10:02 +00:00
|
|
|
return False
|
|
|
|
finally:
|
|
|
|
conn.close()
|
2020-06-27 16:05:34 +00:00
|
|
|
|
|
|
|
class DrupalBcryptAuth(DrupalAuth):
|
|
|
|
def FHashMatches(self, md5, dbhash):
|
|
|
|
return bcrypt.checkpw(md5, dbhash)
|