It may be a bit late, but in order to achieve Windows Authentication Functionality in a C # desktop application, there are two steps that are performed using the following steps.
Step 1: Get the user data currently:
This is pretty straight forward. we can achieve this using the WindowsIdentity class of the System.Security.Principal . This class provides a static getCurrent() method that returns a WindowsIdentity object. Below is the code you can use to get current user information.
Step 2: Verify the Windows credentials provided by the user:
You must request the domain name, username, password from the user in order to pass these values ββfor interaction. This is a bit complicated compared to the previous one, since we need to call the Windows API using IntropServices. To do this, we need to add an extern function declaration, and then call the function. The following code will help you better understand this.
bool issuccess = false; string username = GetloggedinUserName(); if (username.ToLowerInvariant().Contains(txtUserName.Text.Trim().ToLowerInvariant()) && username.ToLowerInvariant().Contains(txtDomain.Text.Trim().ToLowerInvariant())) { issuccess = IsValidateCredentials(txtUserName.Text.Trim(), txtPwd.Text.Trim(), txtDomain.Text.Trim()); } if (issuccess) MessageBox.Show("Successfuly Login !!!"); else MessageBox.Show("User Name / Password / Domain is invalid !!!");
source share