1e41f4b71Sopenharmony_ci# Applying Custom Authentication
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciThe user authentication framework also provides a mechanism for switching from the authentication types supported by the system to the authentication types customized by device vendors.
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciFor example, if the facial or fingerprint authentication provided by the system fails in a payment process, the user can switch to the password authentication defined by the device vendor.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ciBecause the payment password authentication is not a system authentication capability, a navigation button with **Use payment password** must be passed in to initiate the custom authentication.
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ciAfter the user taps this button, the application that initiates the custom authentication will receive a special authentication result returned by the user authentication framework, indicating that the service system authentication is complete and the page for the custom authentication will be started. As a result, the payment password authentication page customized by the service is displayed.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci![](figures/authentication-widget.png)
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciYou can set **WidgetParam.navigationButtonText** to specify the text displayed on the navigation button.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci> **NOTE**
23e41f4b71Sopenharmony_ci> The lock screen password authentication and custom authentication are mutually exclusive.
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci| Authentication Type| Switch to Custom Authentication| 
27e41f4b71Sopenharmony_ci| -------- | -------- |
28e41f4b71Sopenharmony_ci| Lock screen password authentication| × | 
29e41f4b71Sopenharmony_ci| Facial authentication| √ | 
30e41f4b71Sopenharmony_ci| Fingerprint authentication| √ | 
31e41f4b71Sopenharmony_ci| Facial + lock screen password authentication| × | 
32e41f4b71Sopenharmony_ci| Fingerprint + lock screen password authentication| × | 
33e41f4b71Sopenharmony_ci| Facial + fingerprint + lock screen password authentication| × | 
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci## Development Example
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ciTo implement the switchover from a system-supported authentication type to a custom authentication type, the **widgetParam** parameter passed in [initiating authentication](start-authentication.md) must contain **navigationButtonText**.
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ciThe following example only covers how to configure the page for switching to the custom authentication page. You need to implement the process of starting the related page based on the comments in the sample code.
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci```ts
43e41f4b71Sopenharmony_ciimport { BusinessError } from  '@kit.BasicServicesKit';
44e41f4b71Sopenharmony_ciimport { userAuth } from '@kit.UserAuthenticationKit';
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ciconst authParam: userAuth.AuthParam = {
47e41f4b71Sopenharmony_ci  challenge: new Uint8Array([49, 49, 49, 49, 49, 49]),
48e41f4b71Sopenharmony_ci  authType: [userAuth.UserAuthType.FACE],
49e41f4b71Sopenharmony_ci  authTrustLevel: userAuth.AuthTrustLevel.ATL3,
50e41f4b71Sopenharmony_ci};
51e41f4b71Sopenharmony_ci// Set navigationButtonText for the authentication page.
52e41f4b71Sopenharmony_ciconst widgetParam: userAuth.WidgetParam = {
53e41f4b71Sopenharmony_ci  title: 'Verify identity',
54e41f4b71Sopenharmony_ci  navigationButtonText: 'Use password',
55e41f4b71Sopenharmony_ci};
56e41f4b71Sopenharmony_citry {
57e41f4b71Sopenharmony_ci  // Obtain a UserAuthInstance object.
58e41f4b71Sopenharmony_ci  let userAuthInstance = userAuth.getUserAuthInstance(authParam, widgetParam);
59e41f4b71Sopenharmony_ci  console.log('get userAuth instance success');
60e41f4b71Sopenharmony_ci  // Subscribe to the authentication result.
61e41f4b71Sopenharmony_ci  userAuthInstance.on('result', {
62e41f4b71Sopenharmony_ci    onResult(result) {
63e41f4b71Sopenharmony_ci      // If the ResultCode 12500000 is returned, the operation is successful.
64e41f4b71Sopenharmony_ci      console.log('userAuthInstance callback result = ' + JSON.stringify(result));
65e41f4b71Sopenharmony_ci      // If the ResultCode 12500011 is returned, the user taps the navigation button to switch to the custom authentication page.
66e41f4b71Sopenharmony_ci      if (result.result == 12500011) {
67e41f4b71Sopenharmony_ci        // You need to implement the process of starting the custom authentication page.
68e41f4b71Sopenharmony_ci      }
69e41f4b71Sopenharmony_ci    }
70e41f4b71Sopenharmony_ci  });
71e41f4b71Sopenharmony_ci  console.log('auth on success');
72e41f4b71Sopenharmony_ci  userAuthInstance.start();
73e41f4b71Sopenharmony_ci  console.log('auth start success');
74e41f4b71Sopenharmony_ci} catch (error) {
75e41f4b71Sopenharmony_ci  const err: BusinessError = error as BusinessError;
76e41f4b71Sopenharmony_ci  console.error(`auth catch error. Code is ${err?.code}, message is ${err?.message}`);
77e41f4b71Sopenharmony_ci}
78e41f4b71Sopenharmony_ci```
79