def validate_user(f):
    try:
        results = db.query("SELECT * FROM users WHERE username=$username ORDER BY ROWID ASC LIMIT 1",
                           vars={'username': f.username.value})
        user = results[0]

        try:
            valid_hash = pbkdf2_sha256.verify(f.password.value, user.password)
        except ValueError as e:
            web.debug('%s user=%s' % (str(e), user.username))
            valid_hash = None
            pass
            
        date_now = datetime.datetime.now()
        date_expires = datetime.datetime.combine(user.expires, datetime.time.min)
        if date_now <= date_expires:
            if valid_hash:
                web.debug('login_success_hash: user=%s' % user.username)
                return user
            else:
                web.debug('login_failed_hash: incorrect password user=%s, fallback to plaintext' % user.username)
            
                if f.password.value == user.password:
                    web.debug('login_success_plaintext: user=%s' % user.username)
                    return user
                else:
                    web.debug('login_failed_plaintext: incorrect password user=%s' % user.username)
                    return None
        else:
            web.debug('login_failed: expired account user=%s' % user.username)
            return None
    
    except __HOLE__, e:
        web.debug('login_failed: not found user=%s' % f.username.value)
        return None
dataset/ETHPy150Open ab77/netflix-proxy/auth/auth.py/validate_user