VB.NET. Default login form not functioning

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sport Girl
    New Member
    • Jul 2007
    • 42

    VB.NET. Default login form not functioning

    Hi Everybody,

    Please can somebody help me with this little task:

    i created a login form in windows form from the default template in VB.NET but the problem is that it is not functioning even with the correct corresponding code.
    I think the problem resides in event propreties but i am not sure, besides i don't have any idea about how to resolve this thing.

    Can anybody give me an idea?
    Thanks to all volunteers.
    regards
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Don't expect us to guess and solve your problem . Kindly post the code .

    Comment

    • Sport Girl
      New Member
      • Jul 2007
      • 42

      #3
      I am using VB.NET 2008, SQL 2005

      [CODE=vbnet]

      Imports System.Windows. Forms

      Imports System.Data.Sql Client
      Imports System.Security
      Imports System.Security .Cryptography

      Public Class LoginForm
      Inherits System.Windows. Forms.Form

      ' TODO: Insert code to perform custom authentication using the provided username and password
      ' (See http://go.microsoft.co m/fwlink/?LinkId=35339).
      ' The custom principal can then be attached to the current thread's principal as follows:
      ' My.User.Current Principal = CustomPrincipal
      ' where CustomPrincipal is the IPrincipal implementation used to perform authentication.
      ' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object
      ' such as the username, display name, etc.

      Private Sub LoginForm_Load( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load

      InitializeCompo nent()


      End Sub
      Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles OK.Click

      Dim AuthenticationR eader As System.Data.Sql Client.SqlDataR eader

      'Intitalizes connection object
      Dim SqlConnection As New SqlClient.SqlCo nnection
      SqlConnection.C onnectionString = "Server=owner;d atabase=***"

      'Initializes command object to execute statements.
      Dim AuthenticationC ommand As New SqlClient.SqlCo mmand
      AuthenticationC ommand.Connecti on = SqlConnection

      'Declarations
      Dim DBusername As String
      Dim DBuserpassword
      Dim DBuserID As Integer
      Dim DBlogggedname As String
      Dim DBprivilege As String

      If UsernameTextBox .Text.Length = 0 Then


      MessageBox.Show ("You must enter a username", "Invalid Username", MessageBoxButto ns.OK, MessageBoxIcon. Exclamation)
      UsernameTextBox .Focus()



      ElseIf PasswordTextBox .Text.Length = 0 Then

      MessageBox.Show ("You must enter a password", "Invalid Password", MessageBoxButto ns.OK, MessageBoxIcon. Exclamation)
      PasswordTextBox .Focus()
      Else

      DBusername = Me.UsernameText Box.Text
      DBuserpassword = Me.PasswordText Box.Text


      'Executes command
      Dim AuthenticationS tring As String
      AuthenticationS tring = "select * from *** where UserName= '" & UsernameTextBox .Text & "'"

      AuthenticationC ommand.CommandT ext = AuthenticationS tring
      SqlConnection.O pen()
      AuthenticationC ommand.ExecuteN onQuery()

      'Encrypt Password
      Dim md5hasher As New MD5CryptoServic eProvider
      Dim hashedBytes As Byte()
      Dim encoder As New System.Text.UTF 8Encoding

      hashedBytes = md5hasher.Compu teHash(encoder. GetBytes(Passwo rdTextBox.Text) )




      AuthenticationR eader = AuthenticationC ommand.ExecuteR eader()
      If AuthenticationR eader.HasRows Then
      While (Authentication Reader.Read())
      DBusername = AuthenticationR eader("UserName ")
      DBuserpassword = AuthenticationR eader("Password ")
      DBuserID = AuthenticationR eader("UserID")
      DBlogggedname = AuthenticationR eader("Name")
      DBprivilege = Trim(Authentica tionReader("Pri vilege"))
      End While
      Else

      MessageBox.Show ("Invalid username!", "Error", MessageBoxButto ns.OK, MessageBoxIcon. Exclamation)
      UsernameTextBox .Focus()
      Exit Sub
      End If
      AuthenticationR eader.Close()

      SqlConnection.C lose()



      If bHashEquals(has hedBytes, DBuserpassword) Then


      Dim Frame As New Frame()
      Frame.Show()
      Me.Hide()

      Else

      MessageBox.Show ("Invalid password!", "Error", MessageBoxButto ns.OK, MessageBoxIcon. Exclamation)
      PasswordTextBox .Focus()
      End If
      End If




      End Sub
      Private Function bHashEquals(ByV al byHash1 As Byte(), ByVal byHash2() As Byte) As Boolean
      bHashEquals = False
      If byHash1.Length = byHash2.Length Then
      Dim i As Integer
      Do While (i < byHash1.Length) AndAlso (byHash1(i) = byHash2(i))
      i = i + 1
      Loop
      If i = byHash1.Length Then
      bHashEquals = True
      End If
      End If

      End Function

      Private Sub Cancel_Click(By Val sender As System.Object, ByVal e As System.EventArg s) Handles Cancel.Click
      Me.Close()
      End Sub

      End Class

      [/CODE]

      Regards
      Last edited by debasisdas; Apr 17 '08, 12:29 PM. Reason: added code=vbnet tags

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        are you getting any error in the code ?

        run with break points and check the flow of control.

        Comment

        • Sport Girl
          New Member
          • Jul 2007
          • 42

          #5
          the code does not have any errors with the debuggers

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Originally posted by Sport Girl
            the code does not have any errors with the debuggers
            Have you tried stepping through the code to see where it fails?
            Glancing at this, everything seems to look fine....

            -Frinny

            Comment

            • Sport Girl
              New Member
              • Jul 2007
              • 42

              #7
              Well it is always prompting the messagebox "you must enter a username" whenever the situation is, besides the canccel button does not work in closing the form

              Comment

              • Plater
                Recognized Expert Expert
                • Apr 2007
                • 7872

                #8
                Well I see this:
                [code=vbnet]
                If UsernameTextBox .Text.Length = 0 Then
                MessageBox.Show ("You must enter a username", "Invalid Username", MessageBoxButto ns.OK, MessageBoxIcon. Exclamation)
                UsernameTextBox .Focus()
                'etc
                [/code]
                So that message should only be appearing if the UsernameTextBox is empty.

                Comment

                • Sport Girl
                  New Member
                  • Jul 2007
                  • 42

                  #9
                  Well yes but I get this message box even if i had a value for the username and/or a value for the password, besides the buttons are not functionning. the cancel button functions only when i press ESC button from the keybord.

                  I think there is a proprety in validation or something like this but i really don't know what is the problem exactly.

                  Regards

                  Comment

                  • Sport Girl
                    New Member
                    • Jul 2007
                    • 42

                    #10
                    Well yes but I get this message box even if i had a value for the username and/or a value for the password, besides the buttons are not functionning. the cancel button functions only when i press ESC button from the keybord.

                    I think there is a proprety in validation or something like this but i really don't know what is the problem exactly.

                    Regards

                    Comment

                    • Plater
                      Recognized Expert Expert
                      • Apr 2007
                      • 7872

                      #11
                      Set breakpoints in your program and step through it. I think you will find that UsernameTextbox will be empty.
                      Perhaps you mis-named your textboxes? Like mixed up which one is which?

                      Comment

                      Working...