import hashlib


def __mysql_password_hash(passwd):
    """
    Hash string twice with SHA1 and return uppercase hex digest,
    prepended with an asterisk.

    This function is identical to the MySQL PASSWORD() function.
    """
    pass1 = hashlib.sha1(passwd.encode('utf-8')).digest()
    pass2 = hashlib.sha1(pass1).hexdigest()
    return "*" + pass2.upper()