What is the better way for asking for username and password in c#?
I need them to pass in a DirectoryContext
Class call.
I need something like Get-Credential in Powershell, to store username and password in a variable.
Googling for it I found some interesting Class for this job, but there isn't a built in class in framework 4.0 ( exemple: var cred = new credentialDialog()
?
Strong Security is an optional, need just mask the input password field.
Thank you all
You can use PInvoke one of these APIs based on your OS
http://msdn.microsoft.com/en-us/library/aa375177.aspx
http://msdn.microsoft.com/en-us/library/aa375178.aspx
Or use this http://weblogs.asp.net/hernandl/archive/2005/11/21/usercredentialsdialog.aspx that wraps the API call in a slightly more friendly managed library.
You can use the CredUIPromptForCredentials WinAPI function (which generates the standard authentication window as below). See here to use it with C# (or here).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With