def check_auth(self, user, password): try: f = open(self.passwd, 'r') for line in f.readlines(): line = line.strip() # By pass bad lines if not ':' in line: continue if line.startswith('#'): continue elts = line.split(':') name = elts[0] hash = elts[1] if hash[:5] == '$apr1' or hash[:3] == '$1$': h = hash.split('$') magic = h[1] salt = h[2] else: magic = None salt = hash[:2] logger.debug("[Auth htpasswd] PASSWD: %s %s %s" % (name, hash, salt)) # If we match the user, look at the crypt if name == user: if magic == 'apr1': compute_hash = apache_md5_crypt(password, salt) elif magic == '1': compute_hash = unix_md5_crypt(password, salt) else: compute_hash = crypt.crypt(password, salt) # print "Computed hash", compute_hash if compute_hash == hash: logger.info("[Auth htpasswd] Authentication success") return True else: logger.debug( "[Auth htpasswd] Authentication failed invalid name: %s %s" % (name, user)) except Exception, exp: logger.warning( "[Auth htpasswd] Authentication against apache passwd file failed: %s " % (exp)) return False
def check_auth(self, user, password): try: f = open(self.passwd, "r") for line in f.readlines(): line = line.strip() # By pass bad lines if not ":" in line: continue if line.startswith("#"): continue elts = line.split(":") name = elts[0] hash = elts[1] if hash[:5] == "$apr1" or hash[:3] == "$1$": h = hash.split("$") magic = h[1] salt = h[2] else: magic = None salt = hash[:2] logger.debug("[Auth htpasswd] PASSWD: %s %s %s" % (name, hash, salt)) # If we match the user, look at the crypt if name == user: if magic == "apr1": compute_hash = apache_md5_crypt(password, salt) elif magic == "1": compute_hash = unix_md5_crypt(password, salt) else: compute_hash = crypt.crypt(password, salt) # print "Computed hash", compute_hash if compute_hash == hash: logger.info("[Auth htpasswd] Authentication success") return True else: logger.debug("[Auth htpasswd] Authentication failed invalid name: %s %s" % (name, user)) except Exception, exp: logger.warning("[Auth htpasswd] Authentication against apache passwd file failed: %s " % (exp)) return False
def check_auth(self, user, password): try: f = open(self.passwd, 'r') for line in f.readlines(): line = line.strip() # By pass bad lines if not ':' in line: continue if line.startswith('#'): continue elts = line.split(':') name = elts[0] hash = elts[1] if hash[:5] == '$apr1': h = hash.split('$') magic = h[1] salt = h[2] else: magic = None salt = hash[:2] print "PASSWD:", name, hash, salt # If we match the user, look at the crypt if name == user: if magic == 'apr1': compute_hash = apache_md5_crypt(password, salt) else: compute_hash = crypt.crypt(password, salt) print "Computed hash", compute_hash if compute_hash == hash: print "PASSWD : it's good!" return True else: print "PASSWD: bad user", name, user except Exception, exp: print "Checking auth in passwd %s failed : %s " % (self.passwd, exp) return False