1# Authenticating a Domain Account (for System Applications Only)
2
3Authenticate a domain account before unlocking the screen or when the login session fails.
4
5## Before You Start
6
7Import the **osAccount** module.
8
9```ts
10import { osAccount } from '@kit.BasicServicesKit';
11```
12
13## Domain Account Authentication by Password
14
15The domain account can be authenticated by password. You can use [auth](../../reference/apis-basic-services-kit/js-apis-osAccount-sys.md#auth10) to implement this operation. To call this API, the application must have the ohos.permission.ACCESS_USER_AUTH_INTERNAL permission.
16
17**Procedure**
18
191. Request the ohos.permission.ACCESS_USER_AUTH_INTERNAL permission. For details, see [Requesting Permissions for system_basic Applications](../../security/AccessToken/determine-application-mode.md#requesting-permissions-for-system_basic-applications).
20
212. Obtain user input information, including the domain account and its password.
22
23   ```ts
24     let domainAccountInfo: osAccount.DomainAccountInfo = {
25       domain: 'CHINA',
26       accountName: 'zhangsan'
27     }
28     let credential: Uint8Array = new Uint8Array([0]);
29   ```
30
313. Define the callback used to return the authentication result.
32
33   ```ts
34   let callback: osAccount.IUserAuthCallback = {
35     onResult: (resultCode: number, authResult: osAccount.AuthResult) => {
36       console.log('auth resultCode = ' + resultCode);
37       console.log('auth authResult = ' + JSON.stringify(authResult));
38     }
39   }
40   ```
41
424. Use [auth](../../reference/apis-basic-services-kit/js-apis-osAccount-sys.md#auth10) to authenticate the domain account by password.
43
44   ```ts
45   try {
46     osAccount.DomainAccountManager.auth(domainAccountInfo, credential, callback);
47   } catch (err) {
48     console.log('auth exception = ' + JSON.stringify(err));
49   }
50   ```
51
52## Domain Account Authentication by Dialog
53
54If the domain account password is unavailable, display a dialog box to authentication the domain account. You can use [authWithPopup](../../reference/apis-basic-services-kit/js-apis-osAccount-sys.md#authwithpopup10) to implement this operation.
55
56**Procedure**
57
581. Define the callback used to return the authentication result.
59
60   ```ts
61   let callback: osAccount.IUserAuthCallback = {
62     onResult: (resultCode: number, authResult: osAccount.AuthResult) => {
63       console.log('authWithPopup resultCode = ' + resultCode);
64       console.log('authWithPopup authResult = ' + JSON.stringify(authResult));
65     }
66   }
67   ```
68
692. Use [authWithPopup](../../reference/apis-basic-services-kit/js-apis-osAccount-sys.md#authwithpopup10) to authenticate the domain account in a dialog box displayed.
70
71   ```ts
72   try {
73     osAccount.DomainAccountManager.authWithPopup(callback)
74   } catch (err) {
75     console.log('authWithPopup exception = ' + JSON.stringify(err));
76   }
77   ```
78