Skip to content

Instantly share code, notes, and snippets.

@jakoch
Created May 9, 2019 14:13
Show Gist options
  • Save jakoch/345d66c1f76ff20527a59c133acc16ab to your computer and use it in GitHub Desktop.
Save jakoch/345d66c1f76ff20527a59c133acc16ab to your computer and use it in GitHub Desktop.
Authenticate Trac (bugtracker) users against Simple Machines Forum
#!/usr/bin/python
# Authenticate Trac (bugtracker) users against Simple Machines Forum
# Author: Derek Anderson
# Date: 29-01-2008
# Source: http://armyofevilrobots.com/auth_trac_against_smf
try:
from mod_python import apache
except:
pass
def check_smf_auth(user,passwd):
import _mysql, hashlib
db=_mysql.connect("localhost","database_sql1","pw","database_sql1")
db.query("select passwd from smf_members where memberName='%s'"%_mysql.escape_string(user))
r=db.store_result()
hash=r.fetch_row()[0][0]
#print dir(r)
#print hash
myhash=hashlib.sha1(user.lower()+passwd).hexdigest()
#print myhash....
if myhash==hash:
return True
else:
return False
def authenhandler(req):
pw = req.get_basic_auth_pw()
user = req.user
#if user == "spam" and pw == "eggs":
try:
if check_smf_auth(user,pw):
return apache.OK
else:
return apache.HTTP_UNAUTHORIZED
except:
return apache.HTTP_UNAUTHORIZED
if __name__=="__main__":
import sys
print "Console Mode"
print "Help: Arg1 = Name / Arg2 = PW"
print check_smf_auth(sys.argv[1],sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment