VB Help please

renvilo

Well-Known Member
Joined
Jan 28, 2008
Messages
485
Reaction score
0
Hi can someone please help me out.

I have a form with 2 lables (Username, Password) and 2 textbox (textbox1, textbox2) and a OK btn and cancel btn

The program has been done with datasets coz I'm not a pro in programming

I need to validate a user to get access to the database coz it's confidential info and I would like to give some users more access then others. If you have that login form how do I go about this?








Ok this is what I've got for now:

Imports System.Windows.Forms
Imports System.Security.Cryptography


Public Class LoginForm1

Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Me.DialogResult = System.Windows.Forms.DialogResult.OK
Me.Close()
End Sub

Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub

Private Sub LoginForm1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing

If TextBox2.Text.Length = 0 Then
MsgBox("Please enter a password.", MsgBoxStyle.Exclamation, "Password Required")
e.Cancel = True
Return
End If


Dim Username, Password, PasswordHash As String
Dim UserPass As String

UserPass = Me.TBDataSet.Users.PasswordColumn.ColumnName

If Me.DialogResult = Windows.Forms.DialogResult.OK Then
Username = TextBox1.Text
Password = TextBox2.Text
PasswordHash = HashString(Password)

If Userpass = PasswordHash Then

MsgBox("Yes", MsgBoxStyle.OkOnly)
Else
MsgBox("No", MsgBoxStyle.OkOnly)
End If

End If
End Sub


Private Function HashString(ByVal input As String)
'compute the hash value of the password
Dim bytes = System.Text.Encoding.UTF8.GetBytes(input)
Dim hashBytes As Byte()
Dim md5Provider = MD5.Create()
hashBytes = md5Provider.ComputeHash(bytes)
Dim sb As New System.Text.StringBuilder
Dim b As Byte
For Each b In hashBytes
sb.Append(b.ToString("x2"))
Next
Return sb.ToString()
End Function

End Class




Ok, Think the problem is with my IF statement. I don't think this:

UserPass = Me.TBDataSet.Users.PasswordColumn.ColumnName

is working lekker, lol...

Any ideas? I'm comparing the Login with a Table in SQL (The table has Username, Password as fields)
 
RE Help.

Please show code / query where you get the data from the database.

Thank you kindly.
 
Hi Fulmine,

That's the part I'm missing. I don't know how to get the data from SQL (Using dataset) to check it against. All I need is to compare my textbox1.text and textbox2.text to the Table "users" with the Fields "username,Password" in my SQL database.

Database = TB
Table = Users

What can I insert/change to fix this?
 
Top
Sign up to the MyBroadband newsletter
X