CB.
CB.

Reputation: 60938

c# WinForm - how asking for credential with a Dialog form?

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

Upvotes: 6

Views: 17734

Answers (2)

Teoman Soygul
Teoman Soygul

Reputation: 25742

You can use the CredUIPromptForCredentials WinAPI function (which generates the standard authentication window as below). See here to use it with C# (or here).

enter image description here

Upvotes: 5

Bradley Uffner
Bradley Uffner

Reputation: 16991

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.

Upvotes: 5

Related Questions