ECREATE PROC spUserAccount @UserName NVarchar(50),@Password NVarchar(50) AS SELECT UserName,Password FROM tblUser WHERE UserName=@UserName AND Password=@Password
程序代码列表 5:用来找寻符合的使用者帐号密码的预存程序。
同时将整个 ASP 的查询换成如程序代码列表 6 的写法:
<% If Request("UserName")<>"" And Request("Pass")<>"" Then Dim cnn,rec,strSQL,cmd Set cnn=Server.CreateObject("ADODB.Connection") With cnn .ConnectionString=Application("Conn") .Open End With ''''透过ADODB.Command 对象来搭配预存程序,骇客就无法 ''''利用组合 SQL 字符串的方式来侵入系统 Set cmd=Server.CreateObject("ADODB.Command") With cmd .ActiveConnection = cnn .CommandText = "spUserAccount" .CommandType = 4 ''''adCmdStoredProc .Parameters.Append .CreateParameter("UserName", 202, 1, 50, Request("UserName")) ''''202 代表 adVarWChar,1 代表 adParamInput .Parameters.Append .CreateParameter("Password", 202, 1, 50, Request("Pass")) Set rec = .Execute() End With If NOT rec.EOF Then Session("UserName")=Request("UserName") Response.Write "