sql="select uid,pwd from account where uid='" & username & "' and pwd='" & pwd "'" rs.open sql,conn,1,1 if not rs.eof then response.write rs(0) & "歡迎您,您已登陸成功" else response.write "登陸失敗,錯誤的用戶名或密碼" end if ............ 以上程序的漏洞是顯而易見的 我們可以以 用戶名: admin 密碼: a' or '1'='1 輕易以admin的賬號登陸系統 因為我們的sql 變為了 select uid,pwd from account where uid='admin' and pwd='a' or '1'='1' 顯然 uid='admin' and pwd='a' or '1'='1'是恒為成立的所以 rs.eof 為false
正確的寫法應為 sql="select uid,pwd from account where uid='" & username & "' and pwd='" & pwd "'" rs.open sql,conn,1,1 if rs(0)=username and rs(1)=pwd then response.write rs(0) & "歡迎您,您已登陸成功" else response.write "登陸失敗,錯誤的用戶名或密碼" end if