Show / Hide Table of Contents

TryUnsetPassword Method

TryUnsetPassword(ReadOnlyMemory<byte>)

Try to set the OATH application in the YubiKey to no longer be password-protected. This operation requires verifying the current password provided.

C#
public bool TryUnsetPassword(ReadOnlyMemory<byte> password)

Parameters

Type Name Description
ReadOnlyMemory<byte> password

If the OATH application is already password-protected, then this is the current password.

Returns

bool

A boolean, true if the OATH application is unset, and false otherwise.

Exceptions

Type Condition
InvalidOperationException

The YubiKey had some error, such as unreliable connection.

Remarks

If the OATH application is password-protected, the current password must be verified before unsetting. Hence, this method will verify the password. Once that password has been verified, this method will be able to set the OATH application on the YubiKey to no longer be password-protected. If the password does not verify, then this method will return false.

If the OATH application on the YubiKey is not yet password-protected, this method will ignore the password argument, do nothing, and return true.

To see if the OATH application is password-protected or not, look at the property IsPasswordProtected.

For example,

if (oathSession.IsPasswordProtected)
{
    // The OATH application is set to password-Protected,
    // this call will change it to no longer password-protected
    bool isUnset = oathSession.TryUnsetPassword(currentPassword);
}

Note that if the OATH application is password-protected, and the password has already been verified, then it is not necessary to pass in the current password. For example,

if (oathSession.TryVerifyPassword(currentPassword)
{
    bool isUnset =
        oathSession.TryUnsetPassword(ReadOnlyMemory<byte>.Empty);
}
If the password has already been verified in the session, this method will not try to verify the password. That is, the password can be the wrong value or Empty, and if the password has already been verified, this method will succeed.

Note also that the only way to get a false return is if the OATH application is password-protected, the password has not yet been verified in the session, and the provided password is Empty or does not verify.

In this article
Back to top Generated by DocFX