How to remove PasswordVault saved credentials when app is uninstalled?

1.3k views Asked by At

I want the user credentials to be deleted when the window metro app is uninstalled. Its not hapening when I am using password vault for saving passwords. Is there any other way to solve my problem ?

2

There are 2 answers

0
Kraig Brockschmidt - MSFT On

Windows Store apps aren't able to participate in the uninstall process, so you can't do it directly. It does seem that a piece of app state like this should be cleared on uninstall, but it doesn't work that way at present.

You could use your own encryption scheme to store credentials in your own add data, which would be cleared on uninstall. This would be significant work, of course, to be secure.

If you just want to be sure to reacquire credentials after the app is installed, then you can maintain a flag in local app data that indicates whether to load credentials from the locker. On first install, this flag would not exist, so you'd know to collect credentials anew. Once you save in the locker, save a flag in app data that indicates this has happened, so subsequent sessions load from the locker. If the app is uninstalled, the app data contents will be cleared out such that on reinstall and launch you'd collect credentials again.

0
Rich_Ric On

There's another way. You can create a LocalSettings key to store bool value like true if user created and use this LocalSettings key (if not found) to clear vault.

You can implement it like this:

Check, whether to clear Credentials from previous install or not

//WILL RUN ONLY WHEN NO USER FOUND (FROM CURRENT INSTALL)
if (!localSettings.ContainsKey("usersExists"))
{
  IReadOnlyList<PasswordCredential> userDetailsList = loginVault.RetrieveAll();
  foreach (PasswordCredential x in userDetailsList)
   {
    try { loginVault.Remove(x); }
    catch (Exception Error) { Debug.WriteLine(Error); }
   }
   Debug.WriteLine("\nNo User Found!! LoginVault has been reset. All Previous User Details are removed.");
}

Since User Details from previous install is removed now you can create a new user and add localSettings["usersExists"] = true;