Skip to content

Commit c36da87

Browse files
committed
Merged main into live
2 parents c4c0c17 + 4d96e42 commit c36da87

File tree

10 files changed

+406
-382
lines changed

10 files changed

+406
-382
lines changed

.openpublishing.redirection.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8154,6 +8154,21 @@
81548154
"source_path": "hub/apps/design/shell/tiles-and-notifications/index.md",
81558155
"redirect_url": "/windows/uwp/launch-resume/creating-tiles",
81568156
"redirect_document_id": false
8157+
},
8158+
{
8159+
"source_path": "uwp/security/fingerprint-biometrics.md",
8160+
"redirect_url": "/windows/apps/develop/security/fingerprint-biometrics",
8161+
"redirect_document_id": false
8162+
},
8163+
{
8164+
"source_path": "uwp/security/smart-cards.md",
8165+
"redirect_url": "/windows/apps/develop/security/smart-cards",
8166+
"redirect_document_id": false
8167+
},
8168+
{
8169+
"source_path": "uwp/security/credential-locker.md",
8170+
"redirect_url": "/windows/apps/develop/security/credential-locker",
8171+
"redirect_document_id": false
81578172
}
81588173
]
81598174
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
title: Credential locker for Windows apps
3+
description: This article describes how Windows apps can use the Credential Locker to securely store and retrieve user credentials.
4+
ms.date: 08/05/2024
5+
ms.topic: how-to
6+
#customer intent: As a Windows developer, I want to learn how I can integrate the Credential Locker APIs into my native apps to store and retrieve user credentials.
7+
---
8+
9+
# Credential locker for Windows apps
10+
11+
This article describes how Windows apps can use the Credential Locker to securely store and retrieve user credentials, and roam them between devices with the user's Microsoft account.
12+
13+
The Windows Runtime (WinRT) APIs for Credential Locker access are part of the [Windows Software Development Kit (SDK)](https://developer.microsoft.com/windows/downloads/windows-sdk/). These APIs were created for use in Universal Windows Platform (UWP) apps, but they can also be used in WinUI apps or in packaged desktop apps, including WPF and Windows Forms. For more information about using WinRT APIs in your Windows desktop app, see [Call Windows Runtime APIs in desktop apps](/windows/apps/desktop/modernize/desktop-to-uwp-enhance).
14+
15+
## Overview of the sample scenario
16+
17+
For example, you have an app that connects to a service to access protected resources such as media files, or social networking. Your service requires login information for each user. You've built UI into your app that gets the username and password for the user, which is then used to log the user into the service. Using the Credential Locker API, you can store the username and password for your user and easily retrieve them and log the user in automatically the next time they open your app, regardless of what device they're on.
18+
19+
User credentials stored in the Credential Locker do *not* expire, are *not* affected by the [ApplicationData.RoamingStorageQuota](/uwp/api/windows.storage.applicationdata.roamingstoragequota), and will *not* be cleared out due to inactivity like traditional roaming data. However, you can only store up to 20 credentials per app in the Credential Locker.
20+
21+
Credential Locker works a little differently for domain accounts. If there are credentials stored with your Microsoft account, and you associate that account with a domain account (such as the account that you use at work), your credentials will roam to that domain account. However, any new credentials added when signed on with the domain account won’t roam. This ensures that private credentials for the domain aren't exposed outside of the domain.
22+
23+
## Storing user credentials
24+
25+
1. Obtain a reference to the Credential Locker using the [PasswordVault](/uwp/api/Windows.Security.Credentials.PasswordVault) object from the [Windows.Security.Credentials](/uwp/api/Windows.Security.Credentials) namespace.
26+
1. Create a [PasswordCredential](/uwp/api/Windows.Security.Credentials.PasswordCredential) object that contains an identifier for your app, the username and the password, and pass that to the [PasswordVault.Add](/uwp/api/windows.security.credentials.passwordvault.add) method to add the credential to the locker.
27+
28+
```cs
29+
var vault = new Windows.Security.Credentials.PasswordVault();
30+
vault.Add(new Windows.Security.Credentials.PasswordCredential(
31+
"My App", username, password));
32+
```
33+
34+
## Retrieving user credentials
35+
36+
You have several options for retrieving user credentials from the Credential Locker after you have a reference to the [PasswordVault](/uwp/api/Windows.Security.Credentials.PasswordVault) object.
37+
38+
- You can retrieve all the credentials the user has supplied for your app in the locker with the [PasswordVault.RetrieveAll](/uwp/api/windows.security.credentials.passwordvault.retrieveall) method.
39+
- If you know the username for the stored credentials, you can retrieve all the credentials for that username with the [PasswordVault.FindAllByUserName](/uwp/api/windows.security.credentials.passwordvault.findallbyusername) method.
40+
- If you know the resource name for the stored credentials, you can retrieve all the credentials for that resource name with the [PasswordVault.FindAllByResource](/uwp/api/windows.security.credentials.passwordvault.findallbyresource) method.
41+
- Finally, if you know both the username and the resource name for a credential, you can retrieve just that credential with the [PasswordVault.Retrieve](/uwp/api/windows.security.credentials.passwordvault.retrieve) method.
42+
43+
Let’s look at an example where we have stored the resource name globally in an app and we log the user on automatically if we find a credential for them. If we find multiple credentials for the same user, we ask the user to select a default credential to use when logging on.
44+
45+
```cs
46+
private string resourceName = "My App";
47+
private string defaultUserName;
48+
49+
private void Login()
50+
{
51+
var loginCredential = GetCredentialFromLocker();
52+
53+
if (loginCredential != null)
54+
{
55+
// There is a credential stored in the locker.
56+
// Populate the Password property of the credential
57+
// for automatic login.
58+
loginCredential.RetrievePassword();
59+
}
60+
else
61+
{
62+
// There is no credential stored in the locker.
63+
// Display UI to get user credentials.
64+
loginCredential = GetLoginCredentialUI();
65+
}
66+
67+
// Log the user in.
68+
ServerLogin(loginCredential.UserName, loginCredential.Password);
69+
}
70+
71+
private Windows.Security.Credentials.PasswordCredential GetCredentialFromLocker()
72+
{
73+
Windows.Security.Credentials.PasswordCredential credential = null;
74+
75+
var vault = new Windows.Security.Credentials.PasswordVault();
76+
77+
IReadOnlyList<PasswordCredential> credentialList = null;
78+
79+
try
80+
{
81+
credentialList = vault.FindAllByResource(resourceName);
82+
}
83+
catch(Exception)
84+
{
85+
return null;
86+
}
87+
88+
if (credentialList.Count > 0)
89+
{
90+
if (credentialList.Count == 1)
91+
{
92+
credential = credentialList[0];
93+
}
94+
else
95+
{
96+
// When there are multiple usernames,
97+
// retrieve the default username. If one doesn't
98+
// exist, then display UI to have the user select
99+
// a default username.
100+
defaultUserName = GetDefaultUserNameUI();
101+
102+
credential = vault.Retrieve(resourceName, defaultUserName);
103+
}
104+
}
105+
106+
return credential;
107+
}
108+
```
109+
110+
## Deleting user credentials
111+
112+
Deleting user credentials in the Credential Locker is also a quick, two-step process.
113+
114+
1. Obtain a reference to the Credential Locker using the [PasswordVault](/uwp/api/Windows.Security.Credentials.PasswordVault) object from the [Windows.Security.Credentials](/uwp/api/Windows.Security.Credentials) namespace.
115+
1. Pass the credential you want to delete to the [PasswordVault.Remove](/uwp/api/windows.security.credentials.passwordvault.remove) method.
116+
117+
```cs
118+
var vault = new Windows.Security.Credentials.PasswordVault();
119+
vault.Remove(new Windows.Security.Credentials.PasswordCredential(
120+
"My App", username, password));
121+
```
122+
123+
## Best practices
124+
125+
Only use the credential locker for passwords and not for larger data blobs.
126+
127+
Save passwords in the credential locker only if the following criteria are met:
128+
129+
- The user has successfully signed in.
130+
- The user has opted to save passwords.
131+
132+
Never store credentials in plain-text using app data or roaming settings.
133+
134+
## Related content
135+
136+
- [PasswordVault](/uwp/api/Windows.Security.Credentials.PasswordVault)
137+
- [Call Windows Runtime APIs in desktop apps](/windows/apps/desktop/modernize/desktop-to-uwp-enhance)

uwp/security/fingerprint-biometrics.md renamed to hub/apps/develop/security/fingerprint-biometrics.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
---
22
title: Fingerprint biometrics
3-
description: This article explains how to add fingerprint biometrics to your Universal Windows Platform (UWP) app.
4-
ms.assetid: 55483729-5F8A-401A-8072-3CD611DDFED2
5-
ms.date: 02/08/2017
6-
ms.topic: article
7-
keywords: windows 10, uwp, security
8-
ms.localizationpriority: medium
3+
description: This article explains how to add fingerprint biometrics to your packaged Windows app using WinRT APIs from the Windows SDK.
4+
ms.date: 08/05/2024
5+
ms.topic: how-to
6+
#customer intent: As a Windows developer, I want to add fingerprint biometrics to my Windows apps.
97
---
10-
# Fingerprint biometrics
11-
128

9+
# Fingerprint biometrics
1310

11+
This article explains how to add fingerprint biometrics to your Windows app, including a request for fingerprint authentication when the user must consent to a particular action increases the security of your app. For example, you could require fingerprint authentication before authorizing an in-app purchase, or access to restricted resources. Fingerprint authentication is managed using the [UserConsentVerifier](/uwp/api/Windows.Security.Credentials.UI.UserConsentVerifier) class in the [Windows.Security.Credentials.UI](/uwp/api/Windows.Security.Credentials.UI) namespace.
1412

15-
This article explains how to add fingerprint biometrics to your Universal Windows Platform (UWP) app. Including a request for fingerprint authentication when the user must consent to a particular action increases the security of your app. For example, you could require fingerprint authentication before authorizing an in-app purchase, or access to restricted resources. Fingerprint authentication is managed using the [**UserConsentVerifier**](/uwp/api/Windows.Security.Credentials.UI.UserConsentVerifier) class in the [**Windows.Security.Credentials.UI**](/uwp/api/Windows.Security.Credentials.UI) namespace.
13+
The Windows Runtime (WinRT) APIs for fingerprint biometrics are part of the [Windows Software Development Kit (SDK)](https://developer.microsoft.com/windows/downloads/windows-sdk/). These APIs were created for use in Universal Windows Platform (UWP) apps, but they can also be used in WinUI apps or in packaged desktop apps, including WPF and Windows Forms. For more information about using WinRT APIs in your Windows desktop app, see [Call Windows Runtime APIs in desktop apps](/windows/apps/desktop/modernize/desktop-to-uwp-enhance).
1614

1715
## Check the device for a fingerprint reader
1816

19-
20-
To find out whether the device has a fingerprint reader, call [**UserConsentVerifier.CheckAvailabilityAsync**](/uwp/api/windows.security.credentials.ui.userconsentverifier.checkavailabilityasync). Even if a device supports fingerprint authentication, your app should still provide users with an option in Settings to enable or disable it.
17+
To find out whether the device has a fingerprint reader, call [UserConsentVerifier.CheckAvailabilityAsync](/uwp/api/windows.security.credentials.ui.userconsentverifier.checkavailabilityasync). Even if a device supports fingerprint authentication, your app should still provide users with an option in Settings to enable or disable it.
2118

2219
```cs
2320
public async System.Threading.Tasks.Task<string> CheckFingerprintAvailability()
@@ -54,7 +51,7 @@ public async System.Threading.Tasks.Task<string> CheckFingerprintAvailability()
5451
}
5552
catch (Exception ex)
5653
{
57-
returnMessage = "Fingerprint authentication availability check failed: " + ex.ToString();
54+
returnMessage = $"Fingerprint authentication availability check failed: {ex.ToString()}";
5855
}
5956

6057
return returnMessage;
@@ -63,10 +60,8 @@ public async System.Threading.Tasks.Task<string> CheckFingerprintAvailability()
6360

6461
## Request consent and return results
6562

66-
67-
To request user consent from a fingerprint scan, call the [**UserConsentVerifier.RequestVerificationAsync**](/uwp/api/windows.security.credentials.ui.userconsentverifier.requestverificationasync) method. For fingerprint authentication to work, the user must have previously added a fingerprint "signature" to the fingerprint database.
68-
69-
When you call the [**UserConsentVerifier.RequestVerificationAsync**](/uwp/api/windows.security.credentials.ui.userconsentverifier.requestverificationasync), the user is presented with a modal dialog requesting a fingerprint scan. You can supply a message to the **UserConsentVerifier.RequestVerificationAsync** method that will be displayed to the user as part of the modal dialog, as shown in the following image.
63+
1. To request user consent from a fingerprint scan, call the [UserConsentVerifier.RequestVerificationAsync](/uwp/api/windows.security.credentials.ui.userconsentverifier.requestverificationasync) method. For fingerprint authentication to work, the user must have previously added a fingerprint "signature" to the fingerprint database.
64+
1. When you call the [UserConsentVerifier.RequestVerificationAsync](/uwp/api/windows.security.credentials.ui.userconsentverifier.requestverificationasync), the user is presented with a modal dialog requesting a fingerprint scan. You can supply a message to the **UserConsentVerifier.RequestVerificationAsync** method that will be displayed to the user as part of the modal dialog, as shown in the following image.
7065

7166
```cs
7267
private async System.Threading.Tasks.Task<string> RequestConsent(string userMessage)
@@ -114,9 +109,15 @@ private async System.Threading.Tasks.Task<string> RequestConsent(string userMess
114109
}
115110
catch (Exception ex)
116111
{
117-
returnMessage = "Fingerprint authentication failed: " + ex.ToString();
112+
returnMessage = $"Fingerprint authentication failed: {ex.ToString()}";
118113
}
119114

120115
return returnMessage;
121116
}
122-
```
117+
```
118+
119+
## Related content
120+
121+
- [UserConsentVerifier](/uwp/api/Windows.Security.Credentials.UI.UserConsentVerifier)
122+
- [Windows.Security.Credentials.UI namespace](/uwp/api/Windows.Security.Credentials.UI)
123+
- [Call Windows Runtime APIs in desktop apps](/windows/apps/desktop/modernize/desktop-to-uwp-enhance)

hub/apps/develop/security/index.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
---
22
title: Security and identity
33
description: This article provides an index of development features that are related to security and identity scenarios in Windows apps.
4-
ms.topic: article
5-
ms.date: 07/12/2024
4+
ms.topic: overview
5+
ms.date: 08/05/2024
6+
#customer intent: As a Windows developer, I want to learn to use security and identity features available to Windows apps so that I can build more secure apps.
67
---
78

89
# Security and identity
910

1011
This article provides an index of development features that are related to scenarios involving security and identity in Windows apps.
1112

12-
> [!NOTE]
13-
> The [Windows App SDK](../../windows-app-sdk/index.md) currently does not provide APIs related to security and identity scenarios.
14-
1513
## Windows OS features
1614

17-
Windows 10 and later OS releases provide a wide variety of APIs related to graphics scenarios for apps. These features are available via a combination of WinRT and Win32 (C++ and COM) APIs provided by the [Windows SDK](https://developer.microsoft.com/windows/downloads/windows-sdk).
15+
Windows provides a wide variety of APIs related to security and identity scenarios for apps. These features are available via a combination of Windows App SDK, Windows Runtime (WinRT), and Win32 (C++ and COM) APIs provided by the [Windows SDK](https://developer.microsoft.com/windows/downloads/windows-sdk).
16+
17+
### Windows App SDK APIs
18+
19+
The [Windows App SDK](../../windows-app-sdk/index.md) currently does not provide APIs related to security and identity scenarios other than a few helper APIs in the [Microsoft.Windows.Security.AccessControl](/windows/windows-app-sdk/api/winrt/microsoft.windows.security.accesscontrol) namespace. These APIs are related to named object sharing between packaged apps and Win32 applications.
1820

1921
### WinRT APIs
2022

@@ -24,7 +26,10 @@ The following articles provide information about features available via WinRT AP
2426
|---------|-------------|
2527
| [Security](/windows/uwp/security) | Learn about the breadth of security features for Windows apps. |
2628
| [Authentication and user identity](/windows/uwp/security/authentication-and-user-identity) | Windows apps have several options for user authentication, ranging from simple single sign-on (SSO) using Web authentication broker to highly secure two-factor authentication. |
29+
| [Credential locker](credential-locker.md) | This article describes how Windows apps can use the Credential Locker to securely store and retrieve user credentials, and roam them between devices with the user's Microsoft account. |
2730
| [Cryptography](/windows/uwp/security/cryptography) | Learn about cryptography features available to Windows apps. |
31+
| [Fingerprint biometrics](fingerprint-biometrics.md) | This article explains how to add fingerprint biometrics to your Windows app, including a request for fingerprint authentication when the user must consent to a particular action increases the security of your app. |
32+
| [Smart cards](smart-cards.md) | This topic explains how packaged Windows apps can use smart cards to connect users to secure network services. |
2833
| [Windows Hello](windows-hello.md) | This article describes the Windows Hello technology and discusses how developers can implement this technology to protect their apps and backend services. It highlights specific capabilities of Windows Hello that help mitigate threats from conventional credentials and provides guidance about designing and deploying these technologies as part of your packaged Windows apps. |
2934
| [Create a Windows Hello login app](windows-hello-login.md) | Part 1 of a complete walkthrough on how to create a packaged Windows app that uses Windows Hello as an alternative to traditional username and password authentication systems. |
3035
| [Create a Microsoft Passport login service](windows-hello-auth-service.md) | Part 2 of a complete walkthrough on how to use Windows Hello as an alternative to traditional username and password authentication systems in packaged Windows apps. |
@@ -48,3 +53,8 @@ The .NET SDK also provides APIs related to security and identity scenarios for W
4853
| [Security in .NET](/dotnet/standard/security/) | Learn about security concepts and features for all .NET apps. |
4954
| [Security (WPF)](/dotnet/desktop/wpf/security-wpf) | Learn about security concepts and features for WPF apps. |
5055
| [Windows Forms Security](/dotnet/desktop/winforms/windows-forms-security) | Learn about security concepts and features for Windows Forms apps. |
56+
57+
## Related content
58+
59+
- [App lifecycle and system services](../app-lifecycle-and-system-services.md)
60+
- [Develop Windows desktop apps](../index.md)

0 commit comments

Comments
 (0)