10 Replies - 553 Views - Last Post: 23 December 2017 - 04:35 AM Rate Topic: -----

#1 alobi  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 153
  • Joined: 21-January 13

Having problem with login

Posted 21 December 2017 - 02:29 AM

part1 I am comparing with a password in the database. (the password is a combination of plain password and salt). this is created when the user first signs up. This part is working fine, it is saving in database Ok.

Part 2: this is where I am having the issues. when the user returns to login, types the plain password I need to create hashedpassword and compare it with password in the table, if there is a match the user will be allowed to continue. When I run the program, I keep "Sorry no match found or invalid password.

Dim conn As OleDbConnection
        conn = New OleDbConnection(connString)
        conn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Users WHERE [UserName] [email protected] AND [Password] [email protected]", conn)

        cmd.Parameters.AddWithValue("@UserName", Txthash.Text)
        cmd.Parameters.AddWithValue("@Pswrd", hashedpasswrd)
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        ' The following variable hold true if user is found atherwise it holds false
        Dim userFound As Boolean = False
        Dim FirstName As String = " "
        Dim LastName As String = " "
        Dim Title As String = " "
        ' If found
        While dr.Read
            userFound = True
            Title = dr("Title").ToString
            FirstName = dr("FirstName").ToString
            LastName = dr("SurName").ToString

        End While

   


Is This A Good Question/Topic? 0
  • +

Replies To: Having problem with login

#2 andrewsw  Icon User is online

  • blow up my boots
  • member icon

Reputation: 6444
  • View blog
  • Posts: 26,066
  • Joined: 12-December 12

Re: Having problem with login

Posted 21 December 2017 - 03:55 AM

You have misspelt Usernae
Was This Post Helpful? 0
  • +
  • -

#3 alobi  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 153
  • Joined: 21-January 13

Re: Having problem with login

Posted 21 December 2017 - 08:51 AM

Here is my current code and I am still getting ,"Sorry, username or password not valid" , You think maybe the problem is in the query set up, or maybe am not passing the right value for comparing the hashedpasswrd and HPassword? Thanks
 Dim hashedpasswrd As String = ""
        hashedpasswrd = (Hash512(txtPlainPassword.Text, CreateRandomSalt))

        Dim conn As OleDbConnection?
        conn = New OleDbConnection(connString)
        conn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Users WHERE [UserName] [email protected] AND HPassword [email protected]", conn)

        cmd.Parameters.AddWithValue("@UserName", txtUserName.Text)
        cmd.Parameters.AddWithValue("@Pswrd", hashedpasswrd)
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        ' The following variable hold true if user is found atherwise it holds false
        Dim userFound As Boolean = False
        
        

        'checking the result

        If userFound = True Then
            count = 0
            frmMain.Show()
                        Me.Hide()
        Else
            count += 1

            MsgBox("Sorry, username or password not valid", MsgBoxStyle.OkOnly, "Invalid Login")

            If count = 3 Then
                MsgBox("Login failed contact the adminsitrator")
            End If
        End If
        conn.Close()

This post has been edited by alobi: 21 December 2017 - 08:53 AM

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is online

  • blow up my boots
  • member icon

Reputation: 6444
  • View blog
  • Posts: 26,066
  • Joined: 12-December 12

Re: Having problem with login

Posted 21 December 2017 - 09:20 AM

On line 13 you are setting userFound to False, it will still be False on line 19.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13661
  • View blog
  • Posts: 54,531
  • Joined: 12-June 08

Re: Having problem with login

Posted 21 December 2017 - 09:20 AM

Lines 11-13. You need to actually interact with the data reader object to get something to make your determination if a user exists or not.
https://msdn.microso...(v=vs.110).aspx
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is online

  • blow up my boots
  • member icon

Reputation: 6444
  • View blog
  • Posts: 26,066
  • Joined: 12-December 12

Re: Having problem with login

Posted 21 December 2017 - 09:21 AM

(And has your field-name Password changed to HPassword?)
Was This Post Helpful? 0
  • +
  • -

#7 alobi  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 153
  • Joined: 21-January 13

Re: Having problem with login

Posted 21 December 2017 - 07:12 PM

Yes my field name has changed from Password to HPassword
Was This Post Helpful? 0
  • +
  • -

#8 alobi  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 153
  • Joined: 21-January 13

Re: Having problem with login

Posted 22 December 2017 - 04:54 AM

Here is my complete code, it worked fine until I changed the password to hashed password plus salt. From the comment andrewsw and modil123_1 made it sounds like the problem is in the logic,starting with the underlined boolean statement. unfortunately I am yet to figure is out so I will appreciate if I can get a little more help.
 Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
        Dim hashedpasswrd As String = ""
        hashedpasswrd = (Hash512(txtPlainPassword.Text, CreateRandomSalt))

        Dim conn As OleDbConnection
        conn = New OleDbConnection(connString)
        conn.Open()
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM Users WHERE [UserName] [email protected] AND HPassword [email protected]", conn)

        cmd.Parameters.AddWithValue("@UserName", txtUserName.Text)
        cmd.Parameters.AddWithValue("@Pswrd", hashedpasswrd)
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        ' The following variable hold true if user is found atherwise it holds false
        [u]Dim userFound As Boolean = False[/u]
        Dim FirstName As String = " "
        Dim LastName As String = " "
        Dim Title As String = " "
        ' If found
        While dr.Read
            userFound = True
            Title = dr("Title").ToString
            FirstName = dr("FirstName").ToString
            LastName = dr("SurName").ToString

        End While

        'checking the result

        If userFound = True Then
            count = 0
            frmMain.Show()
            frmMain.lblWelcome.Text = "Welcome" & " " & Title & " " & FirstName & " " & LastName
            Me.Hide()
        Else
            count += 1

            MsgBox("Sorry, username or password not valid", MsgBoxStyle.OkOnly, "Invalid Login")

            If count = 3 Then
                MsgBox("Login failed contact the adminsitrator")
            End If
        End If
        conn.Close()

    End Sub

Was This Post Helpful? 0
  • +
  • -

#9 andrewsw  Icon User is online

  • blow up my boots
  • member icon

Reputation: 6444
  • View blog
  • Posts: 26,066
  • Joined: 12-December 12

Re: Having problem with login

Posted 22 December 2017 - 05:10 AM

You need to determine whether your SQL statement successfully returned a row; that is, whether your reader has any rows.

Actually, it looks like you've resolved this. So what is the problem you now have?
Was This Post Helpful? 0
  • +
  • -

#10 alobi  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 153
  • Joined: 21-January 13

Re: Having problem with login

Posted 23 December 2017 - 04:01 AM

The problem that I am having now is this. When I run it, it comes back with information saying the messagebox "Sorry, Username of password not valid. on the third run it will say "Login failed contact the adminitrator." Could you cross check my processing of the password before I compare it HPassword
Was This Post Helpful? 0
  • +
  • -

#11 andrewsw  Icon User is online

  • blow up my boots
  • member icon

Reputation: 6444
  • View blog
  • Posts: 26,066
  • Joined: 12-December 12

Re: Having problem with login

Posted 23 December 2017 - 04:35 AM

step through your code to see what is happening. Check the hashed values and their length.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1