asp登陸源碼
⑴ asp程序實現簡單的注冊,登錄網頁的源代碼
1,(index.asp 用戶登陸頁面)
<!-- #include file="conn.asp" -->
<!-- blog.soowooo.cn 悠悠長假期 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>會員</title>
<style type="text/css">
<!--
body,td,th {
font-family: 宋體;
font-size: 14px;
}
-->
</style>
</head>
<body>
<center>
<p>會員注冊系統</p>
<form name="form1" method="post" action="login.asp">
<table width="34%" border="0">
<tr>
<td width="33%" height="30">用戶名:</td>
<td width="67%" height="30"><input name="username" type="text" id="username" size="15"></td>
</tr>
<tr>
<td height="30">密 碼:</td>
<td height="30"><input name="password" type="password" id="password" size="15"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="Submit" value="確定">
<input type="reset" name="Submit" value="重置"></td>
</tr>
<tr>
<td colspan="2"><a href="reg.asp" target="_self">注冊</a></td>
</tr>
</table>
</form>
</center>
</body>
</html>
2,(login.asp 用戶數據處理文件)
<!-- #include file="conn.asp" -->
<%
'打開資料庫判斷用戶是否存在,info為表名,username為欄位名
set rsc=server.createobject("adodb.recordset")
sqlc="select * from info where username='"&request.Form("username")&"' and password='"&request.Form("password")&"'"
rsc.open sqlc,conn,1,1
session("username")=rsc("username")
session("password")=rsc("password")
session.Timeout=30
set rsc=nothing
response.Redirect("change.asp")
'如果用戶不存在,session("username")為空
%>
3,(change.asp 用戶信息修改頁面)
<!-- #include file="conn.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>修改</title>
<style type="text/css">
<!--
body,td,th {
font-size: 14px;
}
-->
</style></head>
<center>
<body>
<br>
<%
set rsc=server.createobject("adodb.recordset")
sqlc="select * from info where username='"&session("username")&"' and password='"&session("password")&"'"
rsc.open sqlc,conn,1,1
nr=rsc("password")
username=rsc("username")
password=rsc("password")
sex=rsc("sex")
qq=rsc("qq")
mail=rsc("mail")
add=rsc("add")
personalinfo=rsc("personalinfo")
vv=rsc("ntime")
set rsc=nothing
if nr="" then
response.Redirect("index.asp")
end if
if strcomp(nr,request.Form("password"))=0 then
response.Write("歡迎你!"&request.Form("username"))
response.Write("你是在"&vv&"注冊的")
session("username")=request.Form("username")
end if
if session("username")="" then
response.Redirect("index.asp")
end if
%>
<form name="form1" method="post" action="change.asp?ac=ch">
<table width="39%" height="105" border="0" >
<tr>
<td width="27%" height="30">用戶名:</td>
<td width="73%" height="30"><input name="username" type="text" id="username" value="<%=username%>">
*</td>
</tr>
<tr>
<td height="30">密 碼:</td>
<td height="30"><input name="password" type="text" id="password" value="<%=password%>">
*</td>
</tr>
<tr>
<td height="30">性 別:</td>
<td height="30"><input name="sex" type="text" id="sex" value="<%=sex%>"></td>
</tr>
<tr>
<td height="30">QQ:</td>
<td height="30"><input name="qq" type="text" id="qq" value="<%=qq%>"></td>
</tr>
<tr>
<td height="30">Mail:</td>
<td height="30"><input name="mail" type="text" id="mail" value="<%=mail%>"></td>
</tr>
<tr>
<td height="30">地 址:</td>
<td height="30"><input name="add" type="text" id="add" value="<%=add%>"></td>
</tr>
<tr>
<td>介紹</td>
<td><textarea name="personalinfo" cols="30" rows="6" id="personalinfo"><%=personalinfo%></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="修改">
<a href="change.asp?se=y" target="_self">退出系統</a></td>
<% if strcomp(request.QueryString("se"),"y")=0 then
session("username")=""
response.Redirect("index.asp")
end if
%>
</tr>
</table>
</form>
<%
if strcomp(request.QueryString("ac"),"ch")=0 then
set rs=server.createobject("adodb.recordset")
sql="select * from info where username='"&session("username")&"'"
rs.open sql,conn,1,3
rs("username")=request.Form("username")
rs("password")=request.Form("password")
rs("mail")=request.Form("mail")
rs("sex")=request.Form("sex")
rs("qq")=request.Form("qq")
rs("add")=request.Form("add")
rs("personalinfo")=request.Form("personalinfo")
rs.update
set rs=nothing
response.Write("修改完成!")
end if
%>
</body>
</center>
</html>
4,(reg.asp 新用戶注冊頁面)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用戶注冊</title>
<style type="text/css">
<!--
body,td,th {
font-family: 宋體;
font-size: 14px;
}
-->
</style>
</head>
<body>
<center>
用戶注冊<br>
<%
=request.QueryString("msg")
%>
<form name="form1" method="post" action="addnewdata.asp?ac=adser">
<table width="39%" height="105" border="0" >
<tr>
<td width="27%" height="30">用戶名:</td>
<td width="73%" height="30"><input name="username" type="text" id="username">
*</td>
</tr>
<tr>
<td height="30">密碼:</td>
<td height="30"><input name="password" type="password" id="password">
*</td>
</tr>
<tr>
<td height="30">確定密碼:</td>
<td height="30"><input name="password2" type="password" id="password2">
*</td>
</tr>
<tr>
<td height="30">性別:</td>
<td height="30"><input name="sex" type="text" id="sex"></td>
</tr>
<tr>
<td height="30">QQ:</td>
<td height="30"><input name="qq" type="text" id="qq"></td>
</tr>
<tr>
<td height="30">Mail:</td>
<td height="30"><input name="mail" type="text" id="mail"></td>
</tr>
<tr>
<td height="30">地址:</td>
<td height="30"><input name="add" type="text" id="add"></td>
</tr>
<tr>
<td>個人介紹</td>
<td><textarea name="personalinfo" cols="30" rows="6" id="personalinfo"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="提交"></td>
</tr>
</table>
</form>
</center>
</body>
</html>
5,(addnewdata.asp 新用戶注冊數據處理文件)
<!-- #include file="conn.asp" -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>成功</title>
</head>
<body>
<%
ac=request.QueryString("ac")
msg="注冊錯誤信息"
if request.Form("username")="" then
msg=msg&"<br>"&"用戶名不能為空"
end if
if strcomp(cstr(request.Form("password")),cstr(request.Form("password2")))<>0 then
msg=msg&"<br>"&"兩次密碼輸入不同"
end if
if len(request.Form("password"))<6 then
msg=msg&"<br>"&"密碼太簡單"
end if
if strcomp(msg,"注冊錯誤信息")>0 then
response.Redirect("reg.asp?msg="&msg)
end if
if ac="adser" then
set rsc=server.createobject("adodb.recordset")
sql="select * from info where username='"&request.Form("username")&"'"
rsc.open sql,conn,1,1
ck=rsc("username")
set rsc=nothing
if ck<>"" then
msg=msg&"<br>"&"用戶名被人注冊"
response.Redirect("reg.asp?msg="&msg)
end if
dsql="select * from info where id is null"
set rs=server.createobject("adodb.recordset")
rs.open dsql,conn,1,3
rs.addnew
rs("username")=request.Form("username")
rs("password")=request.Form("password")
rs("mail")=request.Form("mail")
rs("sex")=request.Form("sex")
rs("qq")=request.Form("qq")
rs("add")=request.Form("add")
rs("personalinfo")=request.Form("personalinfo")
rs("ntime")=now
rs.update
set rs=nothing
%>
<center>
<a href="index.asp" target="_self">注冊成功,點擊登陸</a>
</center>
<%
end if
%>
</body>
</html>
6,(conn.asp 資料庫連接文件)
<%
'連接資料庫開始
dim conn,rs,sql
on error resume next
dbpath=server.mappath("userinfo.mdb")
set conn=server.createobject("adodb.connection")
conn.open "PROVIDER=Microsoft.jet.OLEDB.4.0;data source="
'創建記錄對象
set rs=server.createobject("adodb.recordset")
%>
7,(userinfo.mdb ACCESS 資料庫)
在ACCESS中建一個表,然後在這個表中建立欄位名稱
表名:info
欄位名稱 數據類型
id 自動編號
username 文本
password 文本
sex 文本
quest 文本
qq 文本
mail 文本
personalinfo 文本
ntime 文本
⑵ 求asp中的登錄注冊的源碼
分5個文件:
1:登錄頁面 login.htm
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>登錄</title>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="33%" height="64" id="table1">
<form name="form" action="go.asp" method="post"><tr>
<td>用戶名:<input name="user"></td>
</tr>
<tr>
<td>密 碼:<input type="password" name="pwd"></td>
</tr>
<tr>
<td><input name="sub" value="登錄" type="submit"></td>
</tr></form>
</table>
</body>
</html>
------------------------
2.資料庫連接文件 conn.asp
<%set rs=server.createobject("adodb.recordset")
conn = "driver={Microsoft Access Driver (*.mdb)};DBQ="&server.mappath("data.mdb")
%>
-------------------------
3:登錄檢測頁面 go.asp
<!-- #include file="conn.asp" -->
<%
pwd=request.Form("pwd")
set rs=server.createobject("adodb.recordset")
sql="select * from user where name='"&request.Form("user")&"'"
rs.open sql,conn,1,1
if rs.eof or rs.bof then'如果用戶名不存在
response.Write"<script language=javascript>alert('請輸入正確的用戶名!');history.go(-1);</script>"
Response.End()
else
if rs("pwd")<>pwd then'如果密碼不對
response.write "<script language=JavaScript>alert('密碼有誤!');history.back();</script>"
else
response.write("登錄成功")'
end if
end if%>
-------------------------------
4。注冊文件 add.asp
<!-- #include file="conn.asp" -->
<%
sql="select * from user where u_user='"&request.Form("user")&"'"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,3
if rs.BOF or rs.EOF then
rs.addnew
rs("name")=request.Form("user")
rs("pwd")=request.Form("pwd")
rs.update
rs.close
set rs=nothing
response.Write ("注冊成功!")
else
rs.close
set rs=nothing
response.write ("此用戶已被注冊")
end if
%>
4。注冊頁面 re.htm
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>注冊</title>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="33%" height="64" id="table1">
<form name="form" action="add.asp" method="post"><tr>
<td>用戶名:<input name="user" size="23"></td>
</tr>
<tr>
<td>密 碼:<input name="pwd" size="23" id="pwd"></td>
</tr>
<tr>
<td><input name="sub" value="注冊" type="submit"></td>
</tr></form>
</table>
</body>
</html>
將這幾個文件和資料庫「data.mdb」放在同一目錄內
資料庫建一個USER表
含name pwd 兩個欄位 文本類型
運行login.htm測試登錄
運行re.htm測試注冊
⑶ 用戶登錄 asp+sql源碼
資料庫建立一個表admin 3個列:Username Passwd oskey(用戶級別)
ODBC數據源創建一個sql的數據源與你建立的資料庫連上。
conn.asp
<%
set conn=server.createobject("adodb.connection")
conn.connectionstring="DSN=ccsw;uid=sa;pwd=1234"
conn.open
%>
index.asp
<html>
<head>
<title>管理登錄</title>
<link rel="stylesheet" href="style.CSS">
<style type="text/css">
<!--
.style1 {color: #9966FF}
.style2 {
font-size: 12pt;
font-weight: bold;
color: #9966FF;
}
.style3 {
font-size: 12pt;
color: #0033CC;
}
.style4 {color: #0000CC}
-->
</style>
</head>
<body>
<div align="center"><center>
<table border="0" cellspacing="1" width="90%">
<tr>
<td> <form method="post" action="chklogin.asp">
<table width="300" border="0" cellspacing="1" cellpadding="0" align="center" bgcolor="#000000">
<tr bgcolor="#FFFFFF">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td height="30" colspan="2" align="right"><div align="center" class="style1 style3"><strong>管理登錄</strong></div></td>
</tr>
<tr>
<td width="33%" align="right" height="30"><span class="style4">用戶名:</span></td>
<td width="67%">
<input name="UserName" maxlength="20" class="smallInput" size="20">
</td>
</tr>
<tr>
<td width="33%" align="right" height="30"><span class="style4">密 碼:</span></td>
<td width="67%">
<input type="password" name="Passwd" maxlength="16" class="smallInput"
size="20">
</td>
</tr>
<tr>
<td colspan="2" height="15"></td>
</tr>
</table>
</td>
</tr>
<tr align="center" bgcolor="#FFFFFF">
<td height="31" bgcolor="#9999FF">
<input type="submit" name="Submit" value="確定" class="buttonface">
<input type="reset" name="Submit2" value="重寫" class="buttonface"></td>
</tr>
</table>
</form>
<p align="center">後台登錄</td>
</tr>
</table>
</center></div>
</body>
</html>
檢查用戶界面:
<!--#include file=articleconn.asp-->
<%
dim rs
UserName1=request.form("UserName")'獲得登錄界面輸入的用戶名
Passwd1=request.form("PassWd")''獲得登錄界面輸入的密碼
set rs=server.CreateObject("ADODB.RecordSet")'建立資料庫連接
rs.open "select * from admin where UserName='" & UserName1 & "' and passwd='"&passwd1&"'",conn,1 '查詢該用戶名和密碼是否存在
if rs.eof or rs.bof then '當沒有符合篩選結果時,則執行下面的句子
response.write "<script language=javascript>"
response.write "alert('用戶或密碼不對!');"
response.write "javascript:history.go(-1);"
response.write "</script>" '用javascript腳本提示用戶
else '如果符合條件的時候
session("UserName")=RS("Username") '新建session,值等於表單傳來的用戶名
session("KEY")=rs("OSKEY")
response.write"<SCRIPT language=JavaScript>alert('登錄成功');"
response.write"this.location.href='admin.asp';</SCRIPT>"
end if '結束if語句
%>