I'm working with a UWP app that makes use of the PasswordVault
class to store things like AWS credentials securely in the Credential Locker.
In all the example code that I can find, any interaction with the locker leads to creating a new instance of a PasswordVault
, even if it's in the same class. For example, the UWP documentation always creates a new instance before reading / writing values to the locker. Even the Credential Locker Sample code from Microsoft shows creating new instances of the PasswordVault
over and over again before doing the actual work against the locker.
My question is - why? Why does a developer need to create a new instance of the vault each time? Is it necessary, or is it just a side-effect of "example code needs to be overly explicit all the time"? Will there be negative side effects when just declaring a field for a PasswordVault
instance, and re-using it for multiple interactions with the Credential Locker? If it's not valid, can you point me at documentation about why not?
In all the example code that I can find, any interaction with the locker leads to creating a new instance of a PasswordVault, even if it's in the same class.
I don't know why the official code author writes like this, I guess he want make the code look easier to understand. For common use, you could create global PasswordVault
instance to store retrieve or delete user credentials.