想用au3写一个账户登陆程序,账户密码都记录在MSSQL数据库里,要如何把输入的账户与数据库中的进行对比验证呢?
下面的代码可以实现从数据库读取账户,但是没办法把输入的账户与数据库中的对比验证。
请求高手指点啊!!
#include <GUIConstantsEx.au3>
;#include <md5.au3>
;#include <StringMD5.au3>
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("driver={SQL Server};server=(local);uid=sa;pwd=123456;database=user")
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.Open("Select * From user")
;建立MSSQL数据库连接,打开user表
GUICreate("登陆", 240, 90, @DesktopWidth / 2 - 120, @DesktopHeight / 2 - 45, -1, 0x00000018)
GUICtrlCreateLabel("账户:", 10, 8, 250, 15)
$ID = GUICtrlCreateInput("", 45, 5, 180, 20)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateLabel("密码:", 10, 38, 250, 15)
$PW = GUICtrlCreateInput("", 45, 35, 180, 20)
$btn = GUICtrlCreateButton("Ok", 90, 65, 60, 20)
GUISetState()
$msg = 0
While $msg <> $GUI_EVENT_CLOSE
$msg = GUIGetMsg()
Select
Case $msg = $btn
ExitLoop
EndSelect
WEnd
If GUICtrlRead($ID) = "" Or GUICtrlRead($PW) = "" Then
MsgBox(4096, "错误", "请输入完整的数据!")
Exit
EndIf
;$c_md5 = md5(GUICtrlRead($PW))
;MsgBox(4096, "账户", GUICtrlRead($ID))
;MsgBox(4096, "密码", $c_md5)
While Not $RS.eof And Not $RS.bof
If @error = 1 Then ExitLoop
If GUICtrlRead($ID) = $RS.Fields(1).value Then ;$RS.Fields(1).value是从数据库读取到的账户名
MsgBox(4096, "yes", $nid)
ExitLoop
EndIf
$RS.movenext
WEnd
$RS.close
$addfld.Close
[ 本帖最后由 298311657 于 2009-2-8 19:00 编辑 ] |