07
08
vb登录代码(读取SQL数据库,Md5加密)
作者:独木舟 日期:2008-07-08
今晚写的vb登录代码,读取SQL数据库,Md5加密
SqlLocalName = "(local)" '连接IP [ 本地用 (local) 外地用IP ]
SqlUserName = "kanoe.cn" '用户名
SqlPassword = "kanoe.cn" '用户密码
SqlDatabaseName = "kanoe.cn" '数据库名
connstr = "Provider=Sqloledb;User ID=" & SqlUserName & "; Password=" & SqlPassword & "; Initial CataLog = " & SqlDatabaseName & "; Data Source=" & SqlLocalName & ";"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
On Error Resume Next
Set conn = New ADODB.Connection
conn.Open connstr
If Err Then
Err.Clear
Set conn = Nothing
MsgBox "数据库连接出错,请检查连接字串。"
Exit Sub
End If
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sqlstr = "Select [UserName],[Password],[Groups] FROM [User] Where [UserName] = '" + Text1.Text + "'"
Rs.Open sqlstr, conn, adOpenStatic, adLockReadOnly, adCmdText
Dim Authenticated As Boolean
Dim cl As Md5
Set cl = New Md5 'class 为你存的类模快名
Authenticated = False
If Rs.EOF = True And Rs.BOF Then
MsgBox "用户不存在!"
Rs.Close
Else
If LCase(cl.Md5_String_Calc(Text2.Text, 16)) = Rs("Password") Then
Authenticated = True
Rs.Close
Else
MsgBox "密码错误"
Rs.Close
End If
End If
If Authenticated = True Then
Form2.Hide
Form1.Show
End If
程序代码
SqlLocalName = "(local)" '连接IP [ 本地用 (local) 外地用IP ]
SqlUserName = "kanoe.cn" '用户名
SqlPassword = "kanoe.cn" '用户密码
SqlDatabaseName = "kanoe.cn" '数据库名
connstr = "Provider=Sqloledb;User ID=" & SqlUserName & "; Password=" & SqlPassword & "; Initial CataLog = " & SqlDatabaseName & "; Data Source=" & SqlLocalName & ";"
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
On Error Resume Next
Set conn = New ADODB.Connection
conn.Open connstr
If Err Then
Err.Clear
Set conn = Nothing
MsgBox "数据库连接出错,请检查连接字串。"
Exit Sub
End If
Dim Rs As ADODB.Recordset
Set Rs = New ADODB.Recordset
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sqlstr = "Select [UserName],[Password],[Groups] FROM [User] Where [UserName] = '" + Text1.Text + "'"
Rs.Open sqlstr, conn, adOpenStatic, adLockReadOnly, adCmdText
Dim Authenticated As Boolean
Dim cl As Md5
Set cl = New Md5 'class 为你存的类模快名
Authenticated = False
If Rs.EOF = True And Rs.BOF Then
MsgBox "用户不存在!"
Rs.Close
Else
If LCase(cl.Md5_String_Calc(Text2.Text, 16)) = Rs("Password") Then
Authenticated = True
Rs.Close
Else
MsgBox "密码错误"
Rs.Close
End If
End If
If Authenticated = True Then
Form2.Hide
Form1.Show
End If
评论: 0 | 引用: 0 | 查看次数: -
发表评论