Пример #1
0
def crypto_pwhash_str_verify(passwd_hash, passwd):
    """
    int crypto_pwhash_str_verify(const char str[128],
                                 const char * const passwd,
                                 unsigned long long passwdlen);
    Verifies the ``passwd`` against a given password hash.

    Returns True on success, raises InvalidkeyError on failure
    :param passwd_hash: saved password hash
    :type passwd_hash: bytes
    :param passwd: password to be checked
    :type passwd: bytes
    :return: success
    :rtype: boolean
    """
    ensure(isinstance(passwd_hash, bytes), raising=TypeError)
    ensure(isinstance(passwd, bytes), raising=TypeError)
    ensure(len(passwd_hash) <= 127,
           "Hash must be at most 127 bytes long",
           raising=exc.ValueError)

    ret = lib.crypto_pwhash_str_verify(passwd_hash, passwd, len(passwd))

    ensure(ret == 0, "Wrong password", raising=exc.InvalidkeyError)
    # all went well, therefore:
    return True
Пример #2
0
def crypto_pwhash_str_verify(passwd_hash, passwd):
    """
    Verifies the ``passwd`` against a given password hash.

    Returns True on success, raises InvalidkeyError on failure
    :param passwd_hash: saved password hash
    :type passwd_hash: bytes
    :param passwd: password to be checked
    :type passwd: bytes
    :return: success
    :rtype: boolean
    """
    ensure(isinstance(passwd_hash, bytes),
           raising=TypeError)
    ensure(isinstance(passwd, bytes),
           raising=TypeError)
    ensure(len(passwd_hash) <= 127,
           "Hash must be at most 127 bytes long",
           raising=exc.ValueError)

    ret = lib.crypto_pwhash_str_verify(passwd_hash, passwd, len(passwd))

    ensure(ret == 0,
           "Wrong password",
           raising=exc.InvalidkeyError)
    # all went well, therefore:
    return True