asp登陆代码!
就这2个表单,先表单验证,在查询数据库,向数据库里插入用户名!
asp登陆代码!
就这2个表单,先表单验证,在查询数据库,向数据库里插入用户名!
1、判断部分 //验证表单
<script language="javascript">
<!--
function isok(theform)
{
if (theform.user_name.value.length<2 || theform.user_name.value.length>10)
{
alert("学生姓名请填写真实姓名!");
theform.user_name.focus();
return (false);
}
if (theform.password.value.length<3 || theform.password.value.length>10)
{
alert("密码最少要3位,最多10位! !");
theform.password.focus();
return (false);
}
if (theform.password_two.value=="")
{
alert("你还有确认密码没填呢!");
theform.password_two.focus();
return (false);
}
if (theform.password_two.value!=theform.password.value)
{
alert("两次密码怎么不一样!");
theform.password_two.focus();
return (false);
}
if (theform.userclass.value=="")
{
alert("你所在的专业班级还没填呢!");
theform.userclass.focus();
return (false);
}
if (theform.num.value=="")
{
alert("你的学生证号还没填呢!");
theform.num.focus();
return (false);
}
return (true);
}
-->
</script>
2、接受数据的表单部分
<form name="form1" method="post" action="表单提交处理页" onSubmit="return isok(this)">
<input name="user_name" type="text" id="user_name" title="请输入您的姓名" size="15">
</label></td>
</tr>
<tr>
<td><div align="center">登陆密码:</div></td>
<td><input name="password" type="password" id="password" title="请输入您的密码" size="15"></td>
</tr>
<tr>
<td><div align="center">重输密码:</div></td>
<td><input name="password_two" type="password" id="password_two" size="15"></td>
</tr>
<tr>
<td><div align="center">专业班级:</div></td>
<td><label>
<input name="userclass" type="text" id="userclass" size="15">
</label></td>
</tr>
<tr>
<td><div align="center">学生证号:</div></td>
<td><label>
<input name="num" type="text" id="num" size="15">
</label></td>
</tr>
</table>
<center>
<p><br />
<input type="submit" name="submit" value="确认提交" />
<input type="reset" name="reset" value="重新输入" /> /
<input type="button" name="button" value="返回首页" onClick=" history.back()" />
</p>
</center>
</form>
3、数据验证保存到数据库部分
<!--#include file="conn.asp"-->
<%
user_name =left(request("user_name"),15) //从左边提取表单文本框name为user_name的值,值前15的!
password =left(request("password"),15)
userclass =left(request("userclass"),15)
num =left(request("num"),15)
if password="" then
response.write "数据有错!"
response.end
end if
Set rs = Server.CreateObject("adodb.recordset")
sql="select * from user where username like '" & user_name & "'" 搜索user表中的字段为username的用户输入表单的user_name值
rs.open sql,conn,1,3
if rs.eof and rs.bof then
rs.addnew
rs("username")=user_name // user_name为user表中的字段
rs("userpwd")=password //将user_name添加到username字段中
rs("userclass")=userclass
rs("usernum")=num
rs.update
rs.movelast
session("user_id")=rs("userid") //将记录集中的userid定义一个session("user_id")变量
session("name")=rs("username")
set rs2=server.createobject("adodb.recordset")
sql="select* from user where username='" &session("name") & "' " //从user表中查询字段为session("name")
rs2.open sql,conn,1,3
rs2("onlinetime")=now
rs2("userip")=Request.serverVariables("REMOTE_ADDR")
rs2.update
session("userip") = rs2("userip")
rs.close
response.redirect "index1.asp"
response.end
else
%>
<a href="userreg.asp">[重新注册]</a>
<%end if%>
你又说登陆,又说插入,搞不明白 你是要新增加 用户与密码,还是验证通过后转向登陆成功页面?
晕,这是个小问题,很容易解决的. 你可以加我100%解决!
'这里引入你数据库的连接文件
'比如:<!--include file="conn.asp"-->
<%
Dim strUserName,strUserPassword
strUserName = Trim(Request.From("UserName"))
strUserPassword = Trim(Request.From("Password"))
if(strUserName = "")then
response.write("<script>alert('姓名不能为空!');history.back();</script>")
response.end()
end if
if(strUserPassword = "")then
response.write("<script>alert('密码不能为空!');history.back();</script>")
response.end()
end if
%>
'做了一半突然对你无语!连链接数据库文件都不例出来。数据库里面有什么表都不知道怎么做下去!
汗,你是直接要代码?不好意思,你这样提问我只能说Sorry!
-----------------------------------------用户登录页面--------------------------------------------------------------------------
<!--#include file="../include/function.asp"-->
<%
response.charset = "GBK"
if session("Admin") <> "" then
call errorHistoryBack("必须退出当前帐号再登陆")
end if
'接收登录信息
if request.form("send") = "登录" then
dim adminname,adminpass,yzm
adminname = request.form("adminname")
adminpass = request.form("adminpass")
yzm = request.form("yzm")
if len(adminname) <2 then
call errorHistoryBack("用户名不得少于2位")
end if
if len(adminpass) < 6 then
call errorHistoryBack("密码不得少于6位")
end if
if len(yzm) <> 4 then
call errorHistoryBack("验证码必须是4位",1)
end if
if not isnumeric(yzm) then
call errorHistoryBack("验证码必须是数字")
end if
'判断服务器中的验证码信息
if cint(yzm) <> Session("CheckCode") then
call errorHistoryBack("验证码错误")
end if
'判断数据库里的字段是否正确
%>
<!--#include file="conn.asp"-->
<!--#include file="../include/md5.asp"-->
<%
dim rs,sql
set rs = server.createobject("adodb.recordset")
sql = "select * from CMS_Admin where CMS_AdminName='"&adminname&"' and CMS_AdminPass='"&md5(adminpass)&"'"
rs.open sql,conn,1,1
if not rs.eof then
'数据正确
session("Admin") = adminname
response.redirect "admin_index.asp"
else
'数据不正确
call close_rs
call close_conn
call errorHistoryBack("用户名或密码不正确")
end if
call close_rs
call close_conn
end if
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>后台管理</title>
<link rel="stylesheet" type="text/css" href="style/admin.css" />
<script type="text/javascript" src="js/login.js"></script>
</head>
<body>
<form method="post" action="admin_login.asp" name="login" id="login">
<h1>管理员登陆</h1>
<label for="username">用户名:<input type="text" name="adminname" id="username" class="text" /></label>
<label for="password">密 码:<input type="password" name="adminpass" id="password" class="text" /></label>
<label for="yzm">验证码:<input type="text" name="yzm" id="yzm" class="text yzm" /> <img src="../include/code.asp" onclick="javascript:this.src='../include/code.asp?tm='+Math.random()" /></label>
<input type="submit" value="登录" onclick="return check();" name="send" class="submit" />
</form>
</body>
</html>
如果需要源文件
请加入100215606编程人生群!!