How to enumerate and retrieve user credentials (Windows Store apps using JavaScript and HTML)
This topic shows how to enumerate and retrieve user credentials stored in credential locker.
Technologies
Instructions
Step 1: Enumerating user credentials
There are two methods that return collections of credentials that can be enumerated. The passwordVault.findAllByResource method returns all credentials stored in the credential locker that are associated with a specific app. The passwordVault.findAllByUserName method returns all credentials for a specific user.
- Create a passwordVault object.
- Call either passwordVault.findAllByResourceor passwordVault.findAllByUserName to return a collection of credentials.
- Create a loop to enumerate the credential collection.
The passwordVault.retrieve method returns a specific credential with a known user and association. The passwordVault.retrieveAll method returns a collection of all stored credentials.
Retrieving user Credentials
- Create a passwordVault object.
- Call passwordVault.retrieve to get a credential for a specific user and app, or call passwordVault.retrieveAll to get a collection of all stored credentials.
Step 2: Enumerating credentials.
The following snippet from the Credential locker sample shows how to enumerate the credentials associated with the specified app. In this case, the app is named "Scenario 2".
try {
var vault = new Windows.Security.Credentials.PasswordVault();
var creds = vault.findAllByResource("Scenario 2");
for (var j = 0; j < creds.size; j++) {
var el = document.createElement('option');
el.text = creds.getAt(i).userName;
document.getElementById("Scenario2Users").add(el, 0);
}
}
Related topics
How to delete user credentials
Build date: 6/11/2013