public async Task RemoveStoredCredential(string username)
{
var userInfoDb = await GetUserInfoDB();
try
{
//go find the one we're updating and actually do it
var userCredentialsCursor = await userInfoDb.SelectAsync(userInfoDb.GetKeys().First(), "credentials", DBReadFlags.AutoLock);
if (userCredentialsCursor != null)
{
using (userCredentialsCursor)
{
do
{
var credential = JsonConvert.DeserializeObject<UserCredential>(userCredentialsCursor.GetString());
if (credential.Username == username)
{
await userCredentialsCursor.DeleteAsync();
}
} while (await userCredentialsCursor.MoveNextAsync());
}
}
}
catch
{
//let it fail
}
var passwordVault = new Windows.Security.Credentials.PasswordVault();
try
{
var windowsCredentials = passwordVault.FindAllByResource("Baconography");
var matchingWindowsCredential = windowsCredentials.FirstOrDefault(windowsCredential => string.Compare(windowsCredential.UserName, username, StringComparison.CurrentCultureIgnoreCase) == 0);
if (matchingWindowsCredential != null)
{
passwordVault.Remove(matchingWindowsCredential);
}
}
catch
{
}
}