sql="select uname,pwd from uinfo where " sql=sql"uname='"request.form("uname")"'" sql=sql" and pwd='"request.form("pwd")"'" rs.open sql,conn,1,1 if rs.eof or rs.bof then response.write "對不起,錯誤的用戶名/密碼!" else response.write "登錄成功!" end if
可能已經有讀者看出來了這段代碼是十分危險的,只要對方知道用戶名就 可以登錄,你可以在密碼框里輸入“' or '1'='1”就可以了,其原理很 簡單,就是利用了sql查詢語句,大家注意,用此方法提交以后的sql語句 變成了:(如果用戶名為administrator) select uname,pwd from uinfo where uname='administrator' and pwd='' or '1'='1' 如果用戶名administrator存在的話那么這個記錄是可以被選出來的,之 后當然就是可以正常登錄了。
解決方案:
sql="select uname,pwd from uinfo where " sql=sql"uname='"request.form("uname")"'" rs.open sql,conn,1,1 if rs.eof or rs.bof then response.write "對不起,本站沒有此用戶!" else if rs.fields("pwd")=trim(request.form("pwd")) then response.write "登錄成功!" else response.write "錯誤的用戶名/密碼!" end if end if