C # WinForm - how to request credentials in a dialog form?

What is the best way to set username and password in C #?

I need them to pass the DirectoryContext class call.

I need something like Get-Credential in Powershell to store the username and password in a variable.

Googling for him. I found an interesting class for this job, but in framework 4.0 there is no built-in class (for example: var cred = new credentialDialog() ?

Strong security is optional, you just need to hide the password field.

Thank you all

+4
source share
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 http://weblogs.asp.net/hernandl/archive/2005/11/21/usercredentialsdialog.aspx , which wraps the API call in a slightly more friendly managed library.

+4
source

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

enter image description here

+4
source

Source: https://habr.com/ru/post/1379378/


All Articles