Beispiel #1
0
        passhash = hashlib.sha512(password).hexdigest()
        try:
            api_key = self.api_keys[(username, passhash)]
            print username, "is already registered"
            callback(False)
        except:
            api_key = newkey()
            self.api_keys[(username, passhash)] = api_key
            print "Creating new user", username, "with", api_key
            callback(api_key)
    
    def authenticate(self, username, password, callback):
        print "Attempting authentication of", username
        
        passhash = hashlib.sha512(password).hexdigest()
        try:
            api_key = self.api_keys[(username, passhash)]
            print "Authentication for", username, "successful"
            callback(api_key)
        except:
            print "Invalid credentials for", user
            callback(False)

if __name__ == "__main__":
    bridge = Bridge(
        api_key=API_KEY['private'])
    
    bridge.publish_service('auth', AuthHandler())
    
    bridge.connect()