📄 login.asp
字号:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
' Project Name: Simple Blog
' Version: 1.1
' Author: James Tang
' Email: fwsous@gmail.com
' Web site: www.fwso.cn
' Copyright (C) 2008 James Tang. All Rights Reserved.
'
' Note: This program can be used for any purpose for free.
'
%>
<!--#include file="conn.asp"-->
<!--#include file="../lib/md5.asp"-->
<%
'***************************************************************************
' Important Notes
' 1. Due to the design problem, the [userName] in the login form refer to the
' [user_email] address in the database, but not the [uesr_name]
'***************************************************************************
On error Resume Next
Dim data, loginRS, loginSQL, isLogin, errorMsg
Dim userID, userName, userEmail, userPassword
isLogin = "false"
errorMsg = ""
userPassword = md5(Trim(Request.Form("userPassword")))
loginSQL = "SELECT * FROM users WHERE user_email='" + Replace(Request.Form("userName"), "'", "''") + "' AND user_password='" + userPassword + "'"
Set loginRS = Server.CreateObject("ADODB.Recordset")
loginRS.open loginSQL, conn, 1, 1
If loginRS.EOF or loginRS.BOF then
isLogin = "false"
Else
isLogin = "true"
userID = loginRS("user_id")
userName = loginRS("user_name")
userEmail = loginRS("user_email")
End If
loginRS.close
Set loginRS = nothing
conn.close
Set conn = nothing
If Err <> "" Then
errorMsg = errorMsg + "Error Number: " + cStr(Err.number) + " Error Description: " + Err.Description
Err.Clear
End If
If isLogin = "true" then
Session("userName") = userName
Session("userID") = userID
Session("userEmail") = userEmail
Session.Timeout = 30
If Request.Form("rememberMe") = "true" then
'TODO Do something with Cookies to keep the user's information
Response.Cookies("userName") = userName
Response.Cookies("userID") = userID
Response.Cookies("userEmail") = userEmail
For Each cookie in Response.Cookies
Response.Cookie(cookie).Expires = Date + 365
Next
End if
End if
data = "{"
data = data + """userName"":""" + Request.Form("userName") + ""","
data = data + """rememberMe"":" + Request.Form("rememberMe") + ","
data = data + """isLogin"":" + isLogin + ","
data = data + """error"":""" + errorMsg + """"
data = data + "}"
Response.Write(data)
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -