Obtaining the Locking Status of a Specified Authentication Type
From API version 22, you can obtain the locking status of a specified authentication type, the number of remaining authentication attempts, or the remaining authentication locking time based on the following development guide.
Available APIs
For details about the parameters, return values, and error codes, see userAuth.getAuthLockState.
| API | Description |
|---|---|
| getAuthLockState(authType: UserAuthType): Promise<AuthLockState> | Obtains the locking status of a specified authentication type to determine whether authentication can be initiated. |
How to Develop
-
Check that the application has the ohos.permission.ACCESS_BIOMETRIC permission. For details about how to request permissions, see Requesting Permissions.
-
Specify an authentication type (UserAuthType) and call the getAuthLockState API to query the authentication locking status.
Example: Obtain the authentication locking status of the PIN authentication type.
async obtainingAuthLockState() : Promise<string> {
try {
Logger.info(`get auth lock state start`);
const authLockState : userAuth.AuthLockState = await userAuth.getAuthLockState(userAuth.UserAuthType.PIN);
if (authLockState.lockoutDuration === userAuth.PERMANENT_LOCKOUT_DURATION) {
Logger.info('the authentication of given authType is permanent locked');
}
const authLockStateContent : string = JSON.stringify(authLockState);
Logger.info('get auth lock state successfully');
return authLockStateContent;
} catch (error) {
const errorMessage : string = `get auth lock state failed, err code is : ${error?.code}, err message is : ${error?.message}`;
Logger.error(errorMessage);
return errorMessage;
}
}