def lookup_password(words, uhpd):
    """
	lookup_password(words, (user, host, port, database)) -> password

	Where 'words' is the output from pgpass.parse()
	"""
    user, host, port, database = uhpd
    for word, (w_host, w_port, w_database, w_user) in words:
        if (w_user == '*' or w_user == user) and (w_host == '*' or w_host ==
            host) and (w_port == '*' or w_port == port) and (w_database ==
            '*' or w_database == database):
            return word
