In your select statement you have
CODE
Dim sql As String = "SELECT UserLogonID, UserPassword FROM MyUsers WHERE UserLogonID = '" & Me.userid.Text & "' AND Userpassword = '" & Me.psword.Text & "'"
I typically would use something like
CODE
SELECT Count(*) from MyUsers WHERE UserLogonID = '" & me.userid.Text & "' AND Userpassword = '" me.psword.Text & "'"
And also, there's no reason to use a reader....just do an execute scalar and then you can test if the value is 0 or not...if it's not then the username and password combination exist...something like
CODE
con.Open()
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = "select count(*) from logins where userNames ='" & _
me.userid.Text & "' and passwords = '" & hash & "'"
cmd.Connection = con
Dim i As String = cmd.ExecuteScalar
If i = "0" Then
MsgBox("Unknown Username and/or Password")
txtUsername.Text = ""
txtOldPassword.Text = ""
txtNewPassword.Text = ""
txtRePassword.Text = ""
Else
However, I would recommend not storing plain text passwords in your database anyway. You could use something like the following function to hash your passwords
CODE
' Hash the password string and return it as a 32 character hex string
Protected Friend Function getMd5Hash(ByVal input As String) As String
Dim md5Hasher As New MD5CryptoServiceProvider()
Dim data As Byte() = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input))
Dim sBuilder As New StringBuilder()
For i As Integer = 0 To data.Length - 1
sBuilder.Append(data(i).ToString("x2"))
Next i
Return sBuilder.ToString()
End Function
Then you can store the passwords as a hash....hash it before you query the database....that way the only thing that ever gets transmitted or read would be an MD5 hash rather than plain text. All you have to do in code is something like
CODE
dim source as string = salting + me.psword.Text
dim hash as string = getMd5Hash(source)
p.s. the salting is a salt string that I declare elsewhere that adds a bit more security to the password
This post has been edited by nofear217: 31 Mar, 2008 - 07:01 AM