Skip to content

Commit 021f9f0

Browse files
oldnewthingalvinashcraft
authored andcommitted
Merged PR 21195: UserConsentVerifier is not limited to fingerprints
UserConsentVerifier is not limited to fingerprints. It can do facial recognition or other Windows Hello-type authentication. Change text and samples to avoid fingerprint assumption. Remove unnecessary `try/catch`. Also add a C++/WinRT example for WinUI3.
1 parent f3a6ba0 commit 021f9f0

7 files changed

Lines changed: 266 additions & 226 deletions

windows.security.credentials.ui/code/BiometricAuth/cs/MainPage.xaml.cs

Lines changed: 52 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -30,51 +30,43 @@ public MainPage()
3030

3131
private async void Grid_Loaded(object sender, RoutedEventArgs e)
3232
{
33-
OutputTextBlock.Text = await CheckFingerprintAvailability();
33+
OutputTextBlock.Text = await CheckDeviceAvailability();
3434
}
3535

3636
private async void AuthenticateButton_Click(object sender, RoutedEventArgs e)
3737
{
38-
var consentResult = await RequestConsent("Fingerprint authentication is required for that action.");
38+
var consentResult = await RequestConsent("Let's make sure it's really you.");
3939
OutputTextBlock.Text += "\n" + consentResult;
4040
}
4141

4242
//<Snippet1>
43-
public async System.Threading.Tasks.Task<string> CheckFingerprintAvailability()
43+
public async System.Threading.Tasks.Task<string> CheckDeviceAvailability()
4444
{
45-
string returnMessage = "";
45+
string returnMessage;
4646

47-
try
48-
{
49-
// Check the availability of fingerprint authentication.
50-
var ucvAvailability = await Windows.Security.Credentials.UI.UserConsentVerifier.CheckAvailabilityAsync();
47+
// Check the availability of device authentication.
48+
var ucvAvailability = await Windows.Security.Credentials.UI.UserConsentVerifier.CheckAvailabilityAsync();
5149

52-
switch (ucvAvailability)
53-
{
54-
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.Available:
55-
returnMessage = "Fingerprint verification is available.";
56-
break;
57-
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.DeviceBusy:
58-
returnMessage = "Biometric device is busy.";
59-
break;
60-
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.DeviceNotPresent:
61-
returnMessage = "No biometric device found.";
62-
break;
63-
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.DisabledByPolicy:
64-
returnMessage = "Biometric verification is disabled by policy.";
65-
break;
66-
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.NotConfiguredForUser:
67-
returnMessage = "The user has no fingerprints registered. Please add a fingerprint to the " +
68-
"fingerprint database and try again.";
69-
break;
70-
default:
71-
returnMessage = "Fingerprints verification is currently unavailable.";
72-
break;
73-
}
74-
}
75-
catch (Exception ex)
50+
switch (ucvAvailability)
7651
{
77-
returnMessage = "Fingerprint authentication availability check failed: " + ex.ToString();
52+
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.Available:
53+
returnMessage = "Authentication device is available.";
54+
break;
55+
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.DeviceBusy:
56+
returnMessage = "Authentication device is busy.";
57+
break;
58+
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.DeviceNotPresent:
59+
returnMessage = "No authentication device found.";
60+
break;
61+
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.DisabledByPolicy:
62+
returnMessage = "Authentication device verification is disabled by policy.";
63+
break;
64+
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.NotConfiguredForUser:
65+
returnMessage = "Please go to Account Settings to set up a PIN or other advanced authentication.";
66+
break;
67+
default:
68+
returnMessage = "Authentication device is currently unavailable.";
69+
break;
7870
}
7971

8072
return returnMessage;
@@ -86,50 +78,36 @@ private async System.Threading.Tasks.Task<string> RequestConsent(string userMess
8678
{
8779
string returnMessage;
8880

89-
if (String.IsNullOrEmpty(userMessage))
90-
{
91-
userMessage = "Please provide fingerprint verification.";
92-
}
81+
// Request the logged on user's consent via authentication device.
82+
var consentResult = await Windows.Security.Credentials.UI.UserConsentVerifier.RequestVerificationAsync(userMessage);
9383

94-
try
84+
switch (consentResult)
9585
{
96-
// Request the logged on user's consent via fingerprint swipe.
97-
var consentResult = await Windows.Security.Credentials.UI.UserConsentVerifier.RequestVerificationAsync(userMessage);
98-
99-
switch (consentResult)
100-
{
101-
case Windows.Security.Credentials.UI.UserConsentVerificationResult.Verified:
102-
returnMessage = "Fingerprint verified.";
103-
break;
104-
case Windows.Security.Credentials.UI.UserConsentVerificationResult.DeviceBusy:
105-
returnMessage = "Biometric device is busy.";
106-
break;
107-
case Windows.Security.Credentials.UI.UserConsentVerificationResult.DeviceNotPresent:
108-
returnMessage = "No biometric device found.";
109-
break;
110-
case Windows.Security.Credentials.UI.UserConsentVerificationResult.DisabledByPolicy:
111-
returnMessage = "Biometric verification is disabled by policy.";
112-
break;
113-
case Windows.Security.Credentials.UI.UserConsentVerificationResult.NotConfiguredForUser:
114-
returnMessage = "The user has no fingerprints registered. Please add a fingerprint to the " +
115-
"fingerprint database and try again.";
116-
break;
117-
case Windows.Security.Credentials.UI.UserConsentVerificationResult.RetriesExhausted:
118-
returnMessage = "There have been too many failed attempts. Fingerprint authentication canceled.";
119-
break;
120-
case Windows.Security.Credentials.UI.UserConsentVerificationResult.Canceled:
121-
returnMessage = "Fingerprint authentication canceled.";
122-
break;
123-
default:
124-
returnMessage = "Fingerprint authentication is currently unavailable.";
125-
break;
126-
}
127-
}
128-
catch (Exception ex)
129-
{
130-
returnMessage = "Fingerprint authentication failed: " + ex.ToString();
86+
case Windows.Security.Credentials.UI.UserConsentVerificationResult.Verified:
87+
returnMessage = "User verified.";
88+
break;
89+
case Windows.Security.Credentials.UI.UserConsentVerificationResult.DeviceBusy:
90+
returnMessage = "Authentication device is busy.";
91+
break;
92+
case Windows.Security.Credentials.UI.UserConsentVerificationResult.DeviceNotPresent:
93+
returnMessage = "No authentication device found.";
94+
break;
95+
case Windows.Security.Credentials.UI.UserConsentVerificationResult.DisabledByPolicy:
96+
returnMessage = "Authentication device verification is disabled by policy.";
97+
break;
98+
case Windows.Security.Credentials.UI.UserConsentVerificationResult.NotConfiguredForUser:
99+
returnMessage = "Please go to Account Settings to set up PIN or other advanced authentication.";
100+
break;
101+
case Windows.Security.Credentials.UI.UserConsentVerificationResult.RetriesExhausted:
102+
returnMessage = "There have been too many failed attempts. Device authentication canceled.";
103+
break;
104+
case Windows.Security.Credentials.UI.UserConsentVerificationResult.Canceled:
105+
returnMessage = "Device authentication canceled.";
106+
break;
107+
default:
108+
returnMessage = "Authentication device is currently unavailable.";
109+
break;
131110
}
132-
133111
return returnMessage;
134112
}
135113
// </Snippet2>

windows.security.credentials.ui/code/BiometricAuth/js/default.js

Lines changed: 52 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -38,90 +38,73 @@
3838

3939

4040
function AuthenticateButton_Click() {
41-
requestConsent("Fingerprint authentication is required for that action.");
41+
requestConsent("Let's make sure it's really you.");
4242
}
4343

4444
//<Snippet1_JS>
4545
function checkFingerprintAvailability() {
46-
try {
47-
// Check the availability of fingerprint authentication.
46+
Windows.Security.Credentials.UI.UserConsentVerifier.checkAvailabilityAsync().then(
47+
function (ucvAvailability) {
4848

49-
Windows.Security.Credentials.UI.UserConsentVerifier.checkAvailabilityAsync().then(
50-
function (ucvAvailability) {
49+
switch (ucvAvailability)
50+
{
51+
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.available:
52+
outputDiv.innerHTML = "<br/>Authentication device is available.";
53+
break;
54+
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.deviceBusy:
55+
outputDiv.innerHTML = "<br/>Authentication device is busy.";
56+
break;
57+
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.deviceNotPresent:
58+
outputDiv.innerHTML = "<br/>No authentication device found.";
59+
break;
60+
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.disabledByPolicy:
61+
outputDiv.innerHTML = "<br/>Authentication device verification is disabled by policy.";
62+
break;
63+
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.notConfiguredForUser:
64+
outputDiv.innerHTML = "<br/>Please go to Account Settings to set up a PIN or other advanced authentication.";
65+
break;
66+
default:
67+
outputDiv.innerHTML = "<br/>Authentication device is currently unavailable.";
68+
break;
69+
}
70+
});
71+
}
72+
}
73+
// </Snippet1_JS>
5174

52-
switch (ucvAvailability)
53-
{
54-
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.available:
55-
outputDiv.innerHTML = "<br/>Fingerprint verification is available.";
75+
// <Snippet2_JS>
76+
function requestConsent(userMessage) {
77+
// Request the logged on user's consent via authentication device.
78+
Windows.Security.Credentials.UI.UserConsentVerifier.requestVerificationAsync(userMessage)
79+
.then(
80+
function (consentResult) {
81+
switch (consentResult) {
82+
case Windows.Security.Credentials.UI.UserConsentVerificationResult.verified:
83+
outputDiv.innerHTML = "<br/>User verified.";
84+
break;
85+
case Windows.Security.Credentials.UI.UserConsentVerificationResult.deviceBusy:
86+
outputDiv.innerHTML = "<br/>Authentication device is busy.";
87+
break;
88+
case Windows.Security.Credentials.UI.UserConsentVerificationResult.deviceNotPresent:
89+
outputDiv.innerHTML = "<br/>No authentication device found.";
5690
break;
57-
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.deviceBusy:
58-
outputDiv.innerHTML = "<br/>Biometric device is busy.";
91+
case Windows.Security.Credentials.UI.UserConsentVerificationResult.disabledByPolicy:
92+
outputDiv.innerHTML = "<br/>Authentication device verification is disabled by policy.";
5993
break;
60-
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.deviceNotPresent:
61-
outputDiv.innerHTML = "<br/>No biometric device found.";
94+
case Windows.Security.Credentials.UI.UserConsentVerificationResult.notConfiguredForUser:
95+
outputDiv.innerHTML = "<br/>Please go to Account Settings to set up a PIN or other advanced authentication.";
6296
break;
63-
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.disabledByPolicy:
64-
outputDiv.innerHTML = "<br/>Biometric verification is disabled by policy.";
97+
case Windows.Security.Credentials.UI.UserConsentVerificationResult.retriesExhausted:
98+
outputDiv.innerHTML = "<br/>There have been too many failed attempts. Device authentication canceled.";
6599
break;
66-
case Windows.Security.Credentials.UI.UserConsentVerifierAvailability.notConfiguredForUser:
67-
outputDiv.innerHTML = "<br/>The user has no fingerprints registered. Please add a fingerprint to the " +
68-
"fingerprint database and try again.";
100+
case Windows.Security.Credentials.UI.UserConsentVerificationResult.canceled:
101+
outputDiv.innerHTML = "<br/>Device authentication canceled.";
69102
break;
70103
default:
71-
outputDiv.innerHTML = "<br/>Fingerprints verification is currently unavailable.";
104+
outputDiv.innerHTML = "<br/>Authentication device is currently unavailable.";
72105
break;
73106
}
74107
});
75-
}
76-
catch (ex) {
77-
outputDiv.innerHTML = "<br/>Fingerprint authentication availability check failed: " + ex.toString();
78-
}
79-
}
80-
// </Snippet1_JS>
81-
82-
// <Snippet2_JS>
83-
function requestConsent(userMessage) {
84-
if (!userMessage) {
85-
userMessage = "Please provide fingerprint verification.";
86-
}
87-
88-
try {
89-
// Request the logged on user's consent via fingerprint swipe.
90-
Windows.Security.Credentials.UI.UserConsentVerifier.requestVerificationAsync(userMessage)
91-
.then(
92-
function (consentResult) {
93-
switch (consentResult) {
94-
case Windows.Security.Credentials.UI.UserConsentVerificationResult.verified:
95-
outputDiv.innerHTML = "<br/>Fingerprint verified.";
96-
break;
97-
case Windows.Security.Credentials.UI.UserConsentVerificationResult.deviceBusy:
98-
outputDiv.innerHTML = "<br/>Biometric device is busy.";
99-
break;
100-
case Windows.Security.Credentials.UI.UserConsentVerificationResult.deviceNotPresent:
101-
outputDiv.innerHTML = "<br/>No biometric device found.";
102-
break;
103-
case Windows.Security.Credentials.UI.UserConsentVerificationResult.disabledByPolicy:
104-
outputDiv.innerHTML = "<br/>Biometric verification is disabled by policy.";
105-
break;
106-
case Windows.Security.Credentials.UI.UserConsentVerificationResult.notConfiguredForUser:
107-
outputDiv.innerHTML = "<br/>The user has no fingerprints registered. Please add a fingerprint to the " +
108-
"fingerprint database and try again.";
109-
break;
110-
case Windows.Security.Credentials.UI.UserConsentVerificationResult.retriesExhausted:
111-
outputDiv.innerHTML = "<br/>There have been too many failed attempts. Fingerprint authentication canceled.";
112-
break;
113-
case Windows.Security.Credentials.UI.UserConsentVerificationResult.canceled:
114-
outputDiv.innerHTML = "<br/>Fingerprint authentication canceled.";
115-
break;
116-
default:
117-
outputDiv.innerHTML = "<br/>Fingerprint authentication is currently unavailable.";
118-
break;
119-
}
120-
});
121-
}
122-
catch (ex) {
123-
outputDiv.innerHTML = "<br/>Fingerprint authentication failed: " + ex.toString();
124-
}
125108
}
126109
// </Snippet2_JS>
127110

windows.security.credentials.ui/userconsentverificationresult.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ Describes the result of a verification operation.
1414

1515
## -enum-fields
1616
### -field Verified:0
17-
The fingerprint was verified.
17+
The user was verified.
1818

1919
### -field DeviceNotPresent:1
20-
There is no biometric verifier device available.
20+
There is no authentication device available.
2121

2222
### -field NotConfiguredForUser:2
23-
A biometric verifier device is not configured for this user.
23+
An authentication verifier device is not configured for this user.
2424

2525
### -field DisabledByPolicy:3
26-
Group policy has disabled the biometric verifier device.
26+
Group policy has disabled authentication device verification.
2727

2828
### -field DeviceBusy:4
29-
The biometric verifier device is performing an operation and is unavailable.
29+
The authentication device is performing an operation and is unavailable.
3030

3131
### -field RetriesExhausted:5
3232
After 10 attempts, the original verification request and all subsequent attempts at the same verification were not verified.
@@ -39,7 +39,7 @@ The verification operation was canceled.
3939

4040
## -examples
4141

42-
The following example shows a method that requests fingerprint verification and returns a message that describes the result based on the UserConsentVerificationResult value.
42+
The following example shows a method that requests verification from an authentication device and returns a message that describes the result based on the UserConsentVerificationResult value.
4343

4444
[!code-csharp[2](../windows.security.credentials.ui/code/BiometricAuth/cs/MainPage.xaml.cs#Snippet2)]
4545

0 commit comments

Comments
 (0)