Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Use windows credentials in a VB 2005 login form for user authentication.

Posted on 2007-08-02
Medium Priority
Last Modified: 2012-06-27
Hello.Im building an application in visual studio 2005 and I want my users in the login section to use their windows account name and password for authentication.I have two text boxes for the username and password and a button which I want to contain authentincation code that will read the credentials from windows and compare it with the user input.I dont know how to proceed.Any ideas?
Question by:Spyros_Savvides
  • 2
  • 2
LVL 53

Accepted Solution

Dhaest earned 2000 total points
ID: 19616066
You can get the username like this:

Private Sub GetUserInfo()Dim UserIdentityInfo As System.Security.Principal.WindowsIdentityDim strMsg As String
UserIdentityInfo = System.Security.Principal.WindowsIdentity.GetCurrent()

strMsg = "User Name: " & UserIdentityInfo.Name & vbCrLf
strMsg = strMsg & " Token: " & UserIdentityInfo.Token.ToString() & vbCrLf
strMsg = strMsg & " Authenticated: " & UserIdentityInfo.AuthenticationType & vbCrLf
strMsg = strMsg & " System: " & UserIdentityInfo.IsSystem & vbCrLf
strMsg = strMsg & " Guest: " & UserIdentityInfo.IsGuest & vbCrLf
strMsg = strMsg & " Anonymous: " & UserIdentityInfo.IsAnonymous & vbCrLf

End Sub

It's impossible to read the windows password !

Author Comment

ID: 19616778
Thank you very much sir.Your solution was very helpful but I think that it is possible to read the password.There is an application called videoguard that authenticates the user only with the windows account name and password.if you want you can check it out.

LVL 53

Expert Comment

ID: 19616811
You can't read it, but propably the program uses some kind of authentication against the active directory. (like http://www.dotnet247.com/247reference/msgs/12/63065.aspx)

Authenticate a user against the Active Directory

Author Comment

ID: 19616875
I will check it out.I have one more question.When I compare the strMessage string with my textbox input I cannot have a succesfull authentication.My code is as follows:

Private Sub Applybt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Applybt.Click
        Dim username As String
        Dim password As String
        Dim pass_confirm As String
        Dim iTotalTabs = Me.TabControl.TabCount()
        Dim X As Integer
        Dim UserIdentityInfo As System.Security.Principal.WindowsIdentity

        UserIdentityInfo = System.Security.Principal.WindowsIdentity.GetCurrent()

 username = UserIdentityInfo.Name & vbCrLf
        password = "1234"
        pass_confirm = "1234"

        If (username = usernametxt.Text) And (password = passwordtxt.Text) And (pass_confirm = confirmpasswordtxt.Text) Then
            Applybt.Enabled = False
            MsgBox("Authentication successfull.")
            LogOffbt.Enabled = True

            For X = 1 To iTotalTabs - 1
                With Me.TabControl.TabPages(X)
                    .Enabled = True
                End With

        ElseIf (usernametxt.Text = "") And (passwordtxt.Text = "") Then
            MsgBox("You must enter a username and a  password.")

        ElseIf (usernametxt.Text = "") Then
            MsgBox("Please enter a username.")

        ElseIf (passwordtxt.Text = "") Then
            MsgBox("Please enter a password.")

        ElseIf (confirmpasswordtxt.Text = "") Then
            MsgBox("You must confirm your password.")
        ElseIf (passwordtxt.Text <> confirmpasswordtxt.Text) Then
            MsgBox("Password and confirmation of password must be the same.")

        Else : MsgBox("Authentication unsuccesfull.Please check your username and password.")

        End If

           End Sub

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question