diff --git a/auth.py b/auth.py index e848c2d..e99f716 100644 --- a/auth.py +++ b/auth.py @@ -1,22 +1,33 @@ import MySQLdb import hashlib import config +import bcrypt +import traceback class NoopAuth(object): def FAuthorized(self, user, passwd): return True class DrupalAuth(object): + def FHashMatches(self, md5, dbhash): + return md5 == dbhash 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 + 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]) finally: cursor.close() except Exception: + traceback.print_exc() return False finally: conn.close() + +class DrupalBcryptAuth(DrupalAuth): + def FHashMatches(self, md5, dbhash): + return bcrypt.checkpw(md5, dbhash) \ No newline at end of file diff --git a/config.py b/config.py index 0931d5e..4a5a826 100644 --- a/config.py +++ b/config.py @@ -8,8 +8,9 @@ BIND_HOSTNAME = "" W = 80 H = 25 # directory to save ANSI pictures to. leave as "." for current directory. no trailing slash required. "" == / -DIR_ANSI = "." -# authorization. Options are "Noop" (make up a username, no password), "Drupal" (fetches from MySQL Drupal database) +DIR_ANSI = "/home/jeremy/sites/marmots/ansi" +# authorization. Options are "Noop" (make up a username, no password), "Drupal" (fetches from MySQL Drupal database), +#"DrupalBcrypt" (fetches from MySQL Drupal database hacked to bcrypt the md5 hash - basically just Glorious Trainwrecks) AUTH = "Noop" # if Drupal, configure these options: #drupaldb = "database" diff --git a/save.sh b/save.sh old mode 100644 new mode 100755 diff --git a/savecycle.sh b/savecycle.sh old mode 100644 new mode 100755 index cabe96b..b6dfbd6 --- a/savecycle.sh +++ b/savecycle.sh @@ -2,7 +2,7 @@ fnnew="whiteboard.marm.`date "+%F_%H-%M"`" -cd /home/jeremy/marmots +cd /home/jeremy/src/marmots save () {