Use Windows Logon credentials in VB 2008 program

PHTech

Senior Member
Joined
Aug 21, 2006
Messages
588
Reaction score
0
Location
Witbank
Hi there...

How can I make my login page in Visual Basic 2008 to use the Windows login credentials...?

If I have a form (login form) which has textboxes USERNAME and PASSWORD, how would I go about creating something that will use the username and password used to log into Windows to log into my program...

Thanx...!
 
Use the Windows API to do the authentication or simply check in your principal objcet for the Thread to check whether the user is authenticated.

Edit: To check if the current user is authenticated, you would be doing the following:
Code:
System.Threading.Thread.CurrentPrincipal.Identity.IsAuthenticated

If you need to authenticate another user, you would be doing this API call:
Code:
C#:
[DllImport("advapi32.dll", SetLastError = true)]
        private static extern bool LogonUser(string lpszUsername,
           string lpszDomain,
           string lpszPassword,
           int dwLogonType,
           int dwLogonProvider,
           ref IntPtr phToken);

VB.Net:
<DllImport("advapi32.dll", SetLastError:=True)> _
    Private Shared Function LogonUser(ByVal lpszUsername As String, 
        ByVal lpszDomain As String, 
        ByVal lpszPassword As String, 
        ByVal dwLogonType As Integer, 
        ByVal dwLogonProvider As Integer, 
        ByRef phToken As IntPtr) As Boolean
 
Last edited:
Do you have any code samples or resource where I can view the code for this type of stuff...? I am kinda new to VB, so there is still alot to learn...
 
Ok... I still don't really understand it, but anyways... I understand the hard-coded username and password with application-defined username & password, but the thing is to use your Windows Login name and password is different... I don't wan't to physically RETRIEVE the usernames for Windows. It must just login straight forward USING the credentials specified at logon, and when entered into the login form of the Windows App...
 
OK... This makes sense a little bit more, but I am totally clueless without a proper tutorial. MSDN library gave me the sample for Hard-coded login with hashing and salting, but that didn't help me alot... And upon searching the MSDN library, I couldn't find anything worthwhile... Sorry for sounding stupid, but this is for an upcoming project I need to do in VISUAL BASIC for my work, and I must learn this stuff at the speed of light...! Thanx...!
 
Well, first question: Are you building a Web application, or a Windows Forms application? It sounds like the latter though...
 
This is a Windows Application... Upon Startup of the application in Windows, it brings up a LOGIN form... If the username and password match the username and password of the Windows user, it must continue to open up the MAIN form...
 
This is a Windows Application... Upon Startup of the application in Windows, it brings up a LOGIN form... If the username and password match the username and password of the Windows user, it must continue to open up the MAIN form...

So the user has to re-type the username and password and you check it to match the username and password for Active Directory?
 
Top
Sign up to the MyBroadband newsletter
X