经典的asp密码验证sql

问题描述:

如果我有一个登录页面获得用户名和密码的用户输入,我将如何将该信息发布到另一个页面,该页面将用于存储潜艇和程序,以便其他页面将包含该页面我可以最小化我输入连接字符串的次数。经典的asp密码验证sql

所以我有login.asp我想登录凭证,以include.asp永远不会被打开,如果用户登录详细信息是正确的,然后将被引导到table.asp。如果不正确,它应该在login.asp页面中显示一条错误消息。

我提供了永远不会被用户低于

Dim objCon, SQL, objRS 

'Connect to Database 
sub connect() 

    Set objCon = CreateObject("ADODB.Connection") 
    Set objRS = CreateObject("ADODB.Recordset") 
    objCon.Open "Provider=SQLOLEDB.1;Password=xxxx;Persist Security Info=True;User ID=xxxx;Initial Catalog=Customer;Data Source=xxxx" 
    SQL = "SELECT * FROM Customer" 
    objRS.open SQL, objCon 

end sub 


sub connectionClose() 

    objRS.close 
    objCon.close 

end sub 

让我发布代码标签,以便它有所帮助。

所以你长了的login.asp,validateLogin.asp,table.asp(他们都得到include.asp)

的login.asp发布凭据validatelogin.asp

一次validatelogin.asp

dim username : username = request.form("username") 
dim password: password = request.form("password") 
'here for security purpose u will want to replace all the single quote in username and password with 2x single quote (you do that to avoid SQL injection form bots/hackers 
username = replace(username ,"'","''") 
password = replace(password,"'","''") 
sqlValidateUser = "SELECT top 1 * FROM Customer where username='"&&"' and password = ''" 
set rsValidateUser = objCon.execute(sqlValidateUser) 
if not rsValidateUser.eof then 
    session("authentified") = "1" 
    response.redirect("table.asp") 
    response.end() 
else 
    response.redirect("YOUR_ERROR_PAGE.asp") 
    response.end() 
end if 
rsValidateUser.close 

然后在include.asp你也会想是这样的:

'Validating if your NOT on login.asp or loginvalidate.asp ... if not Check if your logged in ... if not redirect to error page or login form 
    if not instr(lcase(request.servervariable("url")),"login.asp") > 0 and not instr(lcase(request.servervariable("url")),"validatelogin.asp") > 0 then 
     if session("authentified") = "1" then 
      response.redirect("your_Error_page.asp") 
     end if 
    end if 

不是100%肯定有关include.asp代码我没有验证任何它,但它应该看起来像

可以看到在你的根文件夹include.asp文件的代码创建一个\文件夹中包含。 在\包括添加一个“functions.asp”页面,并把你的通用数据访问功能在该页面。包括没有HTML - 只是服务器端脚本。

在你的认证页面,添加#include指令指向您的文件夹包括:例如:

<!-- #include file = "../includes/functions.asp" --> 

然后从你的身份验证页面,您拨打functions.asp定义的任何功能。

+0

是的我已经做了我的include.asp文件,但我想知道如何设置我的login.asp文件中的include.asp中的变量,因为我的表单将带我到我的table.asp页面,并将不会设置include.asp变量 – 2011-06-10 14:49:26

+0

我会做一个会话变量吗? – 2011-06-10 14:52:01

+1

我会使用一个会话变量是的,一旦他登录设置会话(“验证”)=“1”...然后在你的include包括会话(“验证”)“1”然后response.redirect“YOUR_ERROR_PAGE验证。 asp“Response.end()end if – 2011-06-10 17:36:01