Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

winforms

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

like image 632
CB. Avatar asked Nov 02 '11 20:11

CB.


2 Answers

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.

like image 60
Bradley Uffner Avatar answered Sep 30 '22 13:09

Bradley Uffner


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

like image 24
Teoman Soygul Avatar answered Sep 30 '22 13:09

Teoman Soygul