[Twisted-Python] Re: Adding pb users online
maxwell hammer
nopa90 at msn.com
Sun Jan 25 04:25:49 EST 2004
here is a mysql checker i made,
probably not the best job but you can fix it :)
from twisted.python import components, failure, log
from twisted.cred import error, credentials
from twisted.cred.checkers import ICredentialsChecker
from twisted.enterprise import adbapi
class MysqlPasswordDatabase :
__implements__ = ICredentialsChecker
credentialInterfaces =
(credentials.IUsernamePassword,credentials.IUsernameHashedPassword)
def __init__(self,db_name,db_username,db_password,table_name) :
self.db_name=db_name
self.db_username=db_username
self.db_password=db_password
self.table_name=table_name
self.dbpool = adbapi.ConnectionPool("MySQLdb",host="localhost",
db=db_name,
user=db_username,
passwd=db_password)
def _dbResult(self,result,credentials) :
#print result[0][0]
#print credentials
if result :
if credentials.checkPassword(str(result[0][0])) :
return credentials.username
else :
#print "Failing in password cmp"
return failure.Failure(error.UnauthorizedLogin())
else :
#print "Failing in dbresult"
return failure.Failure(error.UnauthorizedLogin())
def _dbError(self,reason) :
return failure.Failure(error.UnauthorizedLogin())
def requestAvatarId(self,c) :
print "requestAvatarID ",c
d=self.dbpool.runQuery("SELECT pword FROM %s WHERE uname = '%s'" %
(self.table_name,c.username))
d.addCallback(self._dbResult,c)
d.addErrback(self._dbError)
return d
anyway you get the idea, the above code works for me, but it assumes
passwords are stored in plain text.
John Janecek
_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
http://join.msn.com/?page=dept/bcomm&pgmarket=en-ca&RU=http%3a%2f%2fjoin.msn.com%2f%3fpage%3dmisc%2fspecialoffers%26pgmarket%3den-ca
More information about the Twisted-Python
mailing list