用户登录 asp+sql源码

谁能帮我写一个 ASP+SQL的用户登录页

要求详细
1,SQL数据库
2,index.asp
3,conn.asp
4,……
用户登录页要加图形验证

数据库建立一个表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语句
%>
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-08-30
conn.asp代码:
<%
set conn=server.createobject("adodb.connection")
conn.open "driver={sql server};server=数据库地址;uid=sa;pwd=数据密码;database=数据库表名"
%>

登陆界面index.asp代码:
<%
'强制浏览器重新访问服务器下载页面,而不是从缓存读取页面
Response.Buffer = True
Response.Expires = -1
Response.ExpiresAbsolute = Now() - 1
Response.Expires = 0
Response.CacheControl = "no-cache"
%>
<!-- #include file="conn.asp" -->
<!-- #include file="inc/md5.asp" -->
<%
sql="select * from config"
set rs_config=conn.execute(sql)
dianming=rs_config("dianming")
if request("action")="" then
%>
<HTML>
<HEAD>
<TITLE><%=dianming%> - 系统登陆</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<SCRIPT language=JavaScript type=text/JavaScript>
nereidFadeObjects = new Object();
nereidFadeTimers = new Object();
function nereidFade(object, destOp, rate, delta){
if (!document.all)
return
if (object != "[object]"){
setTimeout("nereidFade("+object+","+destOp+","+rate+","+delta+")",0);
return;
}
clearTimeout(nereidFadeTimers[object.sourceIndex]);
diff = destOp-object.filters.alpha.opacity;
direction = 1;
if (object.filters.alpha.opacity > destOp){
direction = -1;
}
delta=Math.min(direction*diff,delta);
object.filters.alpha.opacity+=direction*delta;
if (object.filters.alpha.opacity != destOp){
nereidFadeObjects[object.sourceIndex]=object;
nereidFadeTimers[object.sourceIndex]=setTimeout("nereidFade(nereidFadeObjects["+object.sourceIndex+"],"+destOp+","+rate+","+delta+")",rate);
}
}
</SCRIPT>
<STYLE>
body {font-family: "宋体";font-size: 12px;text-decoration: none;}
td {font-size: 12px;color: #666666;text-decoration: none;line-height: 18px;font-family: "宋体";}
.S1{
font-family: "宋体";
font-weight: bold;
color: #ffffff;
font-size:16px;
text-decoration: none}
</STYLE>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="middle">
<table width="646" height="425" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3">
<img src="images/login_01.gif" width="646" height="114" alt="仓库管理软件"></td>
</tr>
<tr>
<td>
<img src="images/login_02.gif" width="88" height="311" alt=""></td>
<td width="476" height="311" valign="top" background="images/login_03.gif"><br>
<FORM ACTION="index.asp?action=login" METHOD="post" name="loginform">
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="87" height="30" align="right">登录名:</td>
<td valign="middle"><input type="text" name="username" tabindex="1" style="width:160px;"></td>
</tr>
<tr>
<td height="30" align="right">密 码:</td>
<td><INPUT name="pwd" type="password" tabindex="2" style="width:160px;"></td>
</tr>
<tr>
<td height="30" align="right">验证码:</td>
<td height="30"><input type=text name="verifycode" maxLength=6 size="6" tabindex="3" class="textbox">
<font color=red><-请在验证码框输入</font> <IMG style="cursor:hand;" src="inc/verifycode.asp?n=<%=Timer%>" onClick="this.src=this.src;" align="absmiddle"> </td>
</tr>
<tr>
<td height="50" colspan="2" align="center"><input onMouseOver=nereidFade(this,100,10,5) style="FILTER:alpha(opacity=50)" onMouseOut=nereidFade(this,50,10,5) src="images/dl.gif" type="image" tabindex="5" name="enter" border="0" onClick="return checkform()">
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
</table>
</form><hr size=1 color='#efefef' width='80%' align='left'>Copyright © 2007-2009 Powered By <a href="http://www.cnshitou.cn" target="_blank">www.cnshitou.cn</a> 石头网络 Version 2.1<br>
简单进销存管理系统2.1版(仓库管理软件)</td>
<td>
<img src="images/login_04.gif" width="82" height="311" alt=""></td>
</tr>
</table>
</td></tr></table>
<script language=javascript>
<!--
function document.onreadystatechange()
{ var app=navigator.appName;
var verstr=navigator.appVersion;
if(app.indexOf('Netscape') != -1) {
alert('友情提示:\n 您使用的是Netscape浏览器,可能会导致无法使用后台的部分功能。建议您使用 IE6.0 或以上版本。');
} else if(app.indexOf('Microsoft') != -1) {
if (verstr.indexOf('MSIE 3.0')!=-1 || verstr.indexOf('MSIE 4.0') != -1 || verstr.indexOf('MSIE 5.0') != -1 || verstr.indexOf('MSIE 5.1') != -1)
alert('友情提示:\n 您的浏览器版本太低,可能会导致无法使用后台的部分功能。建议您使用 IE6.0 或以上版本。');
}
document.loginform.username.focus();
}
function checkform() {
if(loginform.username.value == '') {
alert('请输入管理账号!');
loginform.username.focus();
return false;
}
if(loginform.pwd.value == '') {
alert('请输入密码!');
loginform.pwd.focus();
return false;
}
if (loginform.verifycode.value == '') {
alert ('请输入验证码!');
loginform.verifycode.focus();
return false;
}
}
//-->
</script>
</html>
<%
else
nowusername=request.form("username")
nowpwd=request.form("pwd")
if Trim(Request.Form("Verifycode"))<>Trim(Session("Verifycode")) then
%>
<script language=javascript>
alert('您输入的后台管理认证码不对,请重新输入!')
window.history.go(-1)
</script>
<%
response.end
end if

userip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If userip = "" Then
userip = Request.ServerVariables("REMOTE_ADDR")
end if

sql="select * from login where (username='"&nowusername&"' and pwd='"&md5(nowpwd)&"') or (bianhao='"&nowusername&"' and pwd='"&md5(nowpwd)&"')"
set rs=conn.execute(sql)
if rs.eof then
conn.execute("insert into rizi(username,class,address) values('"&nowusername&"','登陆失败','"&userip&"')")
%>
<script language=javascript>
alert('登录名称或密码错误!')
window.history.go(-1)
</script>
<%
response.end
end if
conn.execute("insert into rizi(username,class,address) values('"&nowusername&"','登陆成功','"&userip&"')")
set rs_zu=conn.execute("select * from zu_login where id="&rs("id_zu"))
if rs_zu.eof=false then
Response.Cookies("shiwei_zu")=rs_zu("zu")
else
Response.Cookies("shiwei_zu")=""
end if

Response.Cookies("shiwei_username")=rs("username")
Response.Cookies("shiwei_id")=rs("id")
Cookies_Time=1440
Cookies_Time=Dateadd("n",Cookies_Time,Now())
Response.Cookies("shiwei_zu").expires=Cookies_Time
Response.Cookies("shiwei_username").expires=Cookies_Time
Response.Cookies("shiwei_id").expires=Cookies_Time
response.redirect "main.asp"
end if
%>本回答被提问者采纳
第2个回答  2010-08-31
真有好人 啊
相似回答