Rebex
Products Downloads Buy Support Contact
Show / Hide Table of Contents

Argon2.VerifyPassword Method

Namespace: Rebex.Security.Cryptography
Assembly: Rebex.Security.dll (version 7.0.9147)

VerifyPassword(String, ArraySegment<Byte>)

Verifies that the encodedPasswordHash matches the hash of the password. The format of the encoded hash is described in the remarks section of Argon2 class documentation.

Declaration
public static bool VerifyPassword(string encodedPasswordHash, ArraySegment<byte> password)
Parameters
Type Name Description
String encodedPasswordHash

The string that contains an encoded password hash.

ArraySegment<Byte> password

The ArraySegment<T> that contains a password to hash and compare with encodedPasswordHash.

Returns
Type Description
Boolean

True if the encodedPasswordHash matches the password; otherwise false.

Remarks

Encoded hash can be created using a HashPassword method.

Examples
// encodedPasswordHash has been previously created using the HashPassword method.
// Encoded password hash has the following structure:
// $argon2id$v=19$m=65536,t=10,p=4$MTIzNDU2Nzg$GVfTf0x89BTwcW7HhQMYRcgPwOzswaw6UUBWDBXP0kc
public bool CanAuthenticateUser(string encodedPasswordHash, string userPasswordFromUi)
{
    // Convert password to a byte array segment.
    var passwordBytes = new ArraySegment<byte>(Encoding.UTF8.GetBytes(userPasswordFromUi));

    // Returns true when encodePasswordHash matches the hash of userPasswordFromUi;
    // otherwise returns false.
    return Argon2.VerifyPassword(encodedPasswordHash, passwordBytes);
}
Exceptions
Type Condition
ArgumentException

The encodedPasswordHash has invalid format.

See Also
HashPassword(ArraySegment<Byte>, ArraySegment<Byte>, Int32, Argon2Configuration)
HashPassword(ArraySegment<Byte>, Int32, Argon2Configuration)

VerifyPassword(String, String)

Verifies that the encodedPasswordHash matches the hash of the password. The format of the encoded hash is described in the remarks section of Argon2 class documentation.

Declaration
public static bool VerifyPassword(string encodedPasswordHash, string password)
Parameters
Type Name Description
String encodedPasswordHash

The string that contains an encoded password hash.

String password

The String that contains a password to hash compare with encodedPasswordHash. The password is converted to a byte array (using the UTF-8 character encoding) before the hashing operation. When the password is null, it will be treated as an empty string.

Returns
Type Description
Boolean

True if the encodedPasswordHash matches the password; otherwise false.

Remarks

Encoded hash can be created using a HashPassword method.

Examples
// encodedPasswordHash has been previously created using the HashPassword method.
// Encoded hash has the following structure:
// $argon2id$v=19$m=65536,t=10,p=4$MTIzNDU2Nzg$GVfTf0x89BTwcW7HhQMYRcgPwOzswaw6UUBWDBXP0kc
public bool CanAuthenticateUser(string encodedPasswordHash, string userPasswordFromUi)
{
    // Returns true when encodePasswordHash matches the hash of userPasswordFromUi;
    // otherwise returns false.
    return Argon2.VerifyPassword(encodedPasswordHash, userPasswordFromUi);
}
Exceptions
Type Condition
ArgumentException

The encodedPasswordHash has invalid format.

See Also
HashPassword(String, ArraySegment<Byte>, Int32, Argon2Configuration)
HashPassword(String, Int32, Argon2Configuration)
HashPassword(String, Byte[], Int32, Argon2Configuration)

VerifyPassword(String, Byte[])

Verifies that the encodedPasswordHash matches the hash of the password. The format of the encoded hash is described in the remarks section of Argon2 class documentation.

Declaration
public static bool VerifyPassword(string encodedPasswordHash, byte[] password)
Parameters
Type Name Description
String encodedPasswordHash

The string that contains an encoded password hash.

Byte[] password

The byte array that contains a password to hash and compare with encodedPasswordHash. When the password is null, it will be treated as an empty array.

Returns
Type Description
Boolean

True if the encodedPasswordHash matches the password; otherwise false.

Remarks

Encoded hash can be created using a HashPassword method.

Examples
// encodedPasswordHash has been previously created using the HashPassword method.
// Encoded hash has the following structure:
// $argon2id$v=19$m=65536,t=10,p=4$MTIzNDU2Nzg$GVfTf0x89BTwcW7HhQMYRcgPwOzswaw6UUBWDBXP0kc
public bool CanAuthenticateUser(string encodedPasswordHash, byte[] userPasswordFromUi)
{
    // Returns true when encodePasswordHash matches the hash of userPasswordFromUi;
    // otherwise returns false.
    return Argon2.VerifyPassword(encodedPasswordHash, userPasswordFromUi);
}
Exceptions
Type Condition
ArgumentException

The encodedPasswordHash has invalid format.

See Also
HashPassword(Byte[], Byte[], Int32, Argon2Configuration)
HashPassword(Byte[], Int32, Argon2Configuration)
In This Article
  • VerifyPassword(String, ArraySegment<Byte>)
  • VerifyPassword(String, String)
  • VerifyPassword(String, Byte[])
© REBEX ČR s.r.o. Back to top
Privacy policy
Manage cookies