i want query credentials store (or vault called in win8) , login data. msdn unhelpful in case , not want c++ pinvoke approaches.
i know similar questions have been asked here few times, none of solutions work in case. not use metro app programming things passwordvault (as looks) not available. create simple c# wpf desktop application.
ideally should work in several windows versions, win8 prefered.
more want query stored data crm plugin outlook automatically have app log in crm server without having user ask credentials. means, if possible...
so how access windows credentials store?
there nuget library i've been using called credentialmanagement http://nuget.org/packages/credentialmanagement/
the usage pretty simple. wrapped little didn't need to:
public static class credentialutil { public static userpass getcredential(string target) { var cm = new credential {target = target}; if (!cm.load()) { return null; } //userpass class 2 string properties user , pass return new userpass(cm.username, cm.password); } public static bool setcredentials( string target, string username, string password, persistancetype persistencetype) { return new credential {target = target, username = username, password = password, persistancetype = persistencetype}.save(); } public static bool removecredentials(string target) { return new credential { target = target }.delete(); } } sample usage:
credentialutil.setcredentials("foo", "john", "1234", persistancetype.localcomputer); var userpass = credentialutil.getcredential("foo"); console.writeline($"user: {userpass.username} password: {userpass.password}"); credentialutil.removecredentials("foo"); debug.assert(credentialutil.getcredential("foo") == null); if you're interested in implementing yourself, browse source: http://credentialmanagement.codeplex.com/sourcecontrol/latest
the trick there no c# api credential manager. library wraps other .dll entry points nicely. :-)
Comments
Post a Comment