New Problem has Arisen...Need some Login Help

Disasterpiece

Well-known member
Joined
Apr 2, 2003
Messages
47
Location
Blacksburg, VA
*Sigh* Programming is so frustrating for a beginner.

Anyway heres my current Problem:

I have an Access DataBase with Usernames and PWs. The PWs are stored as MD5 encrypted.

I need to know how to write the code to login to a program.

The login form has a Username and Password Textbox.

How do I do this in code?

Thanks.
 
http://www.computerhelp.forum/showthread.php?s=&threadid=71361&highlight=hash

Take a look at Dereks and Buckys responses, I think it will start you on your way.

Hope this is what you were looking for....fairly broad question:)
Do you mean, how do I do the encryption and recognition (link above) or just how do I ask for and recieve input from the user?

Dont mean to be insulting, just dont know where you are in the grand schema of things:p

Jon
 
Neither of those are my issues.

I already have encryption implemented. I also know how to get input from the user. What I dont know how to do is to check what the user inputs against what is in the DB, and would like to know how to do that code-wise.

Thanks
 
Oh Im not mad at you hehe :) Shouldve made myself clearer, its my fault -

Lets look at this scenario:
1. User inputs username and PW, and clicks Login button.
2. On the button click event, store that username into a variable and look for that username in the Database.
3. Also in the event, check to see if the password entered corresponds to the username being looked up.

Im kinda lost on how to do 2 and 3, i.e. looking up data in a database and being able to store it into a new variable.
 
Ok,
No encryption here but this will serve (I think) as a framework for you. (untested)
Using the collection of rows in your dataset (after .fill method),
iterates through looking for the pw item entered, then checks the
username item against that entered in the text box. If they
match, your on your way, other wise you get a messagebox in
your face.

Code:
    Dim dbpassword As String =  txbPassword.text

  Dim dr As DataRow
        For Each dr In dsUsers.Tables("Users").Rows
            If dr.Item("PW").tostring = dbpassword Then
                If dr.Item("Username").tostring = Username.text Then
                    do something like :
                    dim myform as new fclsForm1
                    myform.show
                End If
           Else : MessageBox.Show("You entered an invalid password! Re-enter your password.")
                txbPassword.Text = ""
                 Exit Sub
           End If
        Next

Give it a try, tweak it, let me know how it works.:)

Jon
 
Will do in the next hour or so, Ive resorted to playing video games at the moment to ease the tension of programming :)

Ill post back here with what happens.

Thanks again!
 
After a good 30 min of tweaking I finally got that to work! Much thanks to you!

Heres what I finally ended up with after tweaking:

Code:
encPW.PW1 = encPW.MD5(CStr(txtPassword.Text))
        strUsername = CStr(txtUserName.Text)
        For Each drRow In dtUsers.Rows
            If drRow.Item("PW").ToString = encPW.PW1 Then
                If drRow.Item("Username").ToString = strUsername Then
                    blnLoginCorrect = True
                End If
            End If
        Next

        If blnLoginCorrect = True Then
            frmMainInstance.Show()
            Me.Hide()
        Else
            MessageBox.Show("You entered an invalid password! Re-enter your password.")
            txtPassword.Text = ""
        End If


I just had to create that boolean because if I left the message box in the for loop it would popup for each row that doesnt have your password, which means if youre in the last row you have a lot of clicking to do :)

So this was a great help to me, thanks a bunch!
 
Back
Top