Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Winform login using windows'user

Can I Login A winform using windows user login information. I need password to login my system but I can't get user's password. Is there any thing like password from windows's user to login.

like image 246
Do Thanh Tung Avatar asked Sep 01 '25 02:09

Do Thanh Tung


1 Answers

You might want to try using Ookii's Ookii.Dialogs, which provides a library where you can use a sleek prompt to get the user's password if required for any authentication tasks you wish to process.

Note: after adding a reference to their library, you must include this line along the top lines:

using Ookii.Dialogs;

Here is an example code snippet on how to properly utilize it:

string strUsername = "";
string strPassword = "";

CredentialDialog crDiag = new CredentialDialog();
crDiag.Content = "Your email will be sent using your following credentials.";
crDiag.MainInstruction = "Please enter your email address and password";
crDiag.Target = "MyProgram";

if (crDiag.ShowDialog() == DialogResult.OK)
{
    strUsername = crDiag.UserName;
    strPassword = crDiag.Password;
    //Do whatever you want to do here, if they provided a username and password
}

//Do whatever you want to do here, regardless of whether they did provide or didn't

Below is a screenshot of how the dialog will appear when you call ShowDialog():

The username field can accept things other than email addresses as well. It just depends on what you want to do with it.

enter image description here

like image 143
Kaitlyn Avatar answered Sep 02 '25 19:09

Kaitlyn