简体   繁体   中英

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.

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.

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM