Search code examples
uwpwinjswindows

Windows UWP PasswordVault Not Retrieving


Ok, so I am new to UWP and testing out using the PasswordVault & PasswordCredential classes, but I can't seem to get it to work.

So here's my code:

    var Vault = new Windows.Security.Credentials.PasswordVault();
    var Credentials = new Windows.Security.Credentials.PasswordCredential();
    Credentials.resource = 'testResource';
    Credentials.userName = 'testUser';
    Credentials.password = 'testPass';

    var Add = Vault.add(Credentials);
    Vault.retrieveAll();

    console.log(Vault);

When outputting to the console, it has no resources. Oddly, this seemed to be working earlier, but no longer is. I have stripped it back to literally just the above, and created a new project to ensure nothing else was interfering. Where am I going wrong?

Edit:

I have looked inside the Windows Credentials Manager and found it is adding the credentials, so it's just the retrieving that's failing.


Solution

  • I've cracked it! Clearly something stupid that I was doing. Above I stated that when I was trying to retrieve, I was doing:

    Vault.retrieveAll();
    console.log(Vault);
    

    I was stupidly assuming that when the method called by the object, it would assign the result(s) as a property of that object.

    The method actually just returns the result, so the below is what I actually needed to do:

    var Credentials = Vault.retrieveAll();
    console.log(Credentials);