<s> import MySQLdb <EOL> import settings <EOL> import crypt <EOL> import md5 <EOL> class Papercut_Auth : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . conn = MySQLdb . connect ( host = settings . dbhost , db = settings . dbname , user = settings . dbuser , passwd = settings . dbpass ) <EOL> self . cursor = self . conn . cursor ( ) <EOL> def is_valid_user ( self , username , password ) : <EOL> stmt = """<STR_LIT>""" % ( username ) <EOL> num_rows = self . cursor . execute ( stmt ) <EOL> if num_rows == <NUM_LIT:0> or num_rows is None : <EOL> settings . logEvent ( '<STR_LIT>' % ( username ) ) <EOL> return <NUM_LIT:0> <EOL> db_password = self . cursor . fetchone ( ) [ <NUM_LIT:0> ] <EOL> if len ( db_password ) == <NUM_LIT:32> : <EOL> result = ( db_password != md5 . new ( password ) . hexdigest ( ) ) <EOL> else : <EOL> result = ( db_password != crypt . crypt ( password , password [ : settings . PHP_CRYPT_SALT_LENGTH ] ) ) <EOL> if result : <EOL> settings . logEvent ( '<STR_LIT>' % ( username ) ) <EOL> return <NUM_LIT:0> <EOL> else : <EOL> return <NUM_LIT:1> </s>
