level 1
笨笨的傻呱
楼主
VB2010中,我做的注册界面中的密码用了MD5,其在Access中的密码字段也显示成MD5了,但是在登录界面填写数据库中已有的数据,却显示用户名和密码错误,是否缺了几条代码呢?求高手指教。。。
下面是登录界面的源代码,在没有使用MD5时是能运行的。
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click '登录按钮
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\BS\XT\XT\XT.mdb"
Dim objConn As New OleDbConnection(strConn) '创建一个数据连接
objConn.Open() '打开连接
Dim UserName As String '定义全局变量
UserName = Trim(TextBox1.Text) '将文本框的值赋给定义好的全局变量
Dim PassWord As String '定义全局变量
PassWord = Trim(TextBox2.Text) '将文本框的值赋给定义好的全局变量
Dim strSql As String
strSql = "select * from ZC where 用户名='" & TextBox1.Text & " 'and 密码='" & TextBox2.Text & "'"
If objConn.State = ConnectionState.Closed Then
objConn.Open()
End If
mycommand = New OleDbCommand(strSql, objConn)
mydatareader = mycommand.ExecuteReader
If mydatareader.Read = False Then
MsgBox("用户名不存在或者密码错误", 48, "提示")
Else
Me.Hide()
主界面.Show()
End If
mydatareader.Close()
objConn.Close()
End Sub
下面的是注册中密码部分使用的MD5代码:
Dim md5Hasher As New Security.Cryptography.MD5CryptoServiceProvider()
Dim hashedBytes As Byte()
Dim encoder As New System.Text.UTF8Encoding()
hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(TextBox2.Text))
Dim password As New OleDbParameter("@password", OleDbType.Binary, 6) '定义Insert语句中的参数(密码)
password.Value = hashedBytes
objCmd.Parameters.Add(password)
2012年05月10日 14点05分
1
下面是登录界面的源代码,在没有使用MD5时是能运行的。
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click '登录按钮
Dim strConn As String
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\BS\XT\XT\XT.mdb"
Dim objConn As New OleDbConnection(strConn) '创建一个数据连接
objConn.Open() '打开连接
Dim UserName As String '定义全局变量
UserName = Trim(TextBox1.Text) '将文本框的值赋给定义好的全局变量
Dim PassWord As String '定义全局变量
PassWord = Trim(TextBox2.Text) '将文本框的值赋给定义好的全局变量
Dim strSql As String
strSql = "select * from ZC where 用户名='" & TextBox1.Text & " 'and 密码='" & TextBox2.Text & "'"
If objConn.State = ConnectionState.Closed Then
objConn.Open()
End If
mycommand = New OleDbCommand(strSql, objConn)
mydatareader = mycommand.ExecuteReader
If mydatareader.Read = False Then
MsgBox("用户名不存在或者密码错误", 48, "提示")
Else
Me.Hide()
主界面.Show()
End If
mydatareader.Close()
objConn.Close()
End Sub
下面的是注册中密码部分使用的MD5代码:
Dim md5Hasher As New Security.Cryptography.MD5CryptoServiceProvider()
Dim hashedBytes As Byte()
Dim encoder As New System.Text.UTF8Encoding()
hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(TextBox2.Text))
Dim password As New OleDbParameter("@password", OleDbType.Binary, 6) '定义Insert语句中的参数(密码)
password.Value = hashedBytes
objCmd.Parameters.Add(password)