openharmony 鸿蒙 obtain-auth-lock-state-capabilities

2026-08-25 浏览 (1)

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.

APIDescription
getAuthLockState(authType: UserAuthType): Promise<AuthLockState>Obtains the locking status of a specified authentication type to determine whether authentication can be initiated.

How to Develop

  1. Check that the application has the ohos.permission.ACCESS_BIOMETRIC permission. For details about how to request permissions, see Requesting Permissions.

  2. 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;
  }
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 cancel-authentication

openharmony 鸿蒙 obtain-enrolled-state-capabilities

openharmony 鸿蒙 apply-custom-authentication

openharmony 鸿蒙 Readme-EN

openharmony 鸿蒙 perceive-adjust-authentication-process

openharmony 鸿蒙 start-authentication

openharmony 鸿蒙 user-auth-icon

openharmony 鸿蒙 user-authentication-overview

openharmony 鸿蒙 user-authentication-glossary

openharmony 鸿蒙 prerequisites

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/OuAmhgJi