Link to home
Start Free TrialLog in
Avatar of aplogic
aplogic

asked on

WinForms: Windows Authentication

Hello, I'm creating a few winform applications that will integrate with my company's webform intranet.  The webforms use Windows authentication, so employees only have to use their IIS login.  I wish to do the same for the winforms but I haven't been able to find anything on the internet explaining how to do this.  Yes, it is a little redundant since the user is already logged into the machine, but I just want to verify that it is that user running the application.  So is there any way to use windows authentication in a winform?
Thanks,
Christion
Avatar of aplogic
aplogic

ASKER

Or is there (after asking for their username and password) a windows authentication function that takes the username and password and returns a boolean if the user authenticates?
try using the WindowsIdentity class

Dim theIdentity As WindowsIdentity = WindowsIdentity.GetCurrent()
Dim thePrincipal As New WindowsPrincipal(theIdentity)

If  thePrincipal.Identity.IsAuthenticated Then
  <tasks>        
End if

you have to import the namespace Principal:
Imports System.Security.Principal
Avatar of aplogic

ASKER

Hmm... that checks to see if the person is logged into the computer (and you can also then check roles, etc).  
But I want to verify that the person opening my program is the same person logged into the computer.  So I want to ask them their windows username and password again (basically like windows authentication for web forms).
then u can pull the user name from WindowsPrincipal and compare with the user input:

If  thePrincipal.Identity.Name=TextBox1.Tex Then
  <tasks>
End if
Avatar of aplogic

ASKER

What about the password- how do I verify that they put in their correct Windows password?
ASKER CERTIFIED SOLUTION
Avatar of EBatista
EBatista

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aplogic

ASKER

That was exactly what I was looking for.  
Thanks!
Christion