【asp源码栏目提醒】:网学会员为需要asp源码的朋友们搜集整理了asp用户注册、用户登录程序 - 互联网相关资料,希望对各位网友有所帮助!
asp用户注册、用户登录程序
asp用户注册、用户登录程序2010-06-20 21161说明 本文介绍一个用
ASP编写的网站的注册、登录系统。
用户注册时须输入用户名、密码等个人信息下一次访问时用该用户名和密码登录登录后成功后方可察看有关网页内容。
如果没有登录直接访问其他页面则重定向回注册页面。
该系统中包含了检验和加密等功能具有较好的实用性。
2网页功能与代码 2.1登录控制网页-default.
asp 功能检查是否通过用户名、密码验证。
如果已经通过显示登录成功如果没有通过则重定向至登录网页-logon.
asp。
代码 LANGUAGEVBSCRIPTCODEPAGE936 --include filesecurity.
asp-- html head meta http-equivContent-Typecontenttext/htmlcharsetgb2312 title欢迎光临/title /head if sessionpassaction1then检验在session中是否有登录成功的信息 response.Redirectlogon.
asp Response.End end if body h1 aligncenter/h1 h1 aligncenter登录成功/h1 /body /html 提示在实际使用时将上述代码插入需要控制打开的网页中即可 2.2登录网页-logon.
asp 功能用户界面以及将用户填写信息发送到检验网页-validate.
asp 代码 LANGUAGEVBSCRIPTCODEPAGE936 html head meta http-equivContent-Typecontenttext/htmlcharsetgb2312 title注册/title /head body p/p p/p table width600border0aligncenter tr td h2 aligncenter用户登录/h2 form nameform1methodpostactionvalidate.
asp table width67border1aligncentercellspacing0bordercolor0000FF tr th width25用户名/th td width75input nameusertypetextsize20 /td /tr th密码/th td input namepasswordtypepasswordsize20/td /tr th附加码/th td input typetextnameotherpwdsize20classbutton1 dim temprnd随机生成附加码 Randomize temprndcstrInt9999-10001Rnd1000 response.Writetemprnd input typehiddennamereotherpwdvaluetemprnd直接将生成附加码发送至检验网页 /td /tr th/th td input typesubmitnameSubmitvalue提交 input typesubmitnametesetvalue重写/td /tr /table /form /td /tr /table h2 aligncenter/h2 /body /html 2.3检验网页-validate.
asp LANGUAGEVBSCRIPTCODEPAGE936 htm l head meta http-equivContent-Typecontenttext/htmlcharsetgb2312 title登录网页/title /head body p/p p/p h2 aligncenter Session.Timeout10限制Session中保存登录成功信息的时间 dim db以下连上数据库建立一个Connection对象实例db set dbServer.CreateobjectADODB.Connection db.OpenDBQServer.Mappathmaindata.asaDRIVERMicrosoft Access Driver.mdb dim strSqlrsstrSql1 strSqlSelectFrom user set rsdb.executestrSql dim a1a2nampswotherpwdreotherpwd a1Request.Formuser a2Request.Formpassword otherpwdRequest.Formotherpwd reotherpwdRequest.Formreotherpwd do while not rs.Eof namrsuser_name rem利用decrypt函数还原用户密码 pswdecryptrspassword if reotherpwd otherpwd then Response.Write附加码不对p Response.Writea hreflogon.
asp重新登录/a Response.End end if if a1nam and a2psw then sessionpassaction1将登录成功的信息保存在session中以便备查如default.
asp中 response.Redirectdefault.
asp如果用户名、密码正确登录成功引导到另一张网页 Response.End end if rs.movenext loop Response.Write用户信息不正确p Response.Writea hreflogon.
asp重新登录/a /h2 /body /html 2.4注册网页-login.
asp 功能用户注册界面且将注册信息发送至检验及添加至数据库的网页-insert.
asp 代码 LANGUAGEVBSCRIPTCODEPAGE936 html head meta http-equivContent-Typecontenttext/htmlcharsetgb2312 title注册/title /head body p/p p/p table width600border0aligncenter tr td h2 aligncenter用户注册/h2 form nameform1methodpostactioninsert.
asp table width67border1aligncentercellspacing0bordercolor0000FF tr th width25用户名/th td width75input typetextnameuser 必须填写/td /tr th密码/th td input typepasswordnamepassword /td /tr th width25确认密码/th td width75input typepasswordnamepassword2 /td /tr th width25性别/th td width75input typeradionamesexvalue男 input typeradionamesexvalue女 女/td /tr th width25爱好/th td width75input typecheckboxnamelovevalue音乐 音乐 input typecheckboxnamelovevalue计算机 计算机/td /tr th width25职业/th td width75select namecareersize1 option valueselected请选择/option option value教育业教育业/option option value金融业金融业/option option value其他其他/option /select/td /tr th width25简介/th td width75textarea nameintroductioncols40rows2wraspsoft/textarea/td /tr th/th td input typesubmitnameSubmitvalue提交 input typesubmitnametesetvalue重写/td /tr /table /form /td /tr /table h2 aligncenter/h2 /body /html 2.5检验注册信息将合格信息添加数据库网页-insert.
asp 功能检验注册信息是否合格。
如用户名是否已经注册过密码、确认密码是否相同。
代码 LANGUAGEVBSCRIPTCODEPAGE936 --include filesecurity.
asp-- html head meta http-equivContent-Typecontenttext/htmlcharsetgb2312 title注册结果/title /head body p/p p/p h2 aligncenter dim db以下连上数据库建立一个Connection对象实例db set dbServer.CreateobjectADODB.Connection db.OpenDBQServer.Mappathmaindata.asaDRIVERMicrosoft Access Driver.mdb dim strSqlrsstrSql1 strSqlSelectFrom user set rsdb.executestrSql dim a1a2b2c2a3a4a5a6i a1Request.Formuser a2Request.Formpassword b2Request.Formpassword2 a3Request.Formsex a4Request.Formlove a5Request.Formcareer a6Request.Formintroduction 下面是检查用户名和密码是否填写完整 if trima1or trima2then Response.Write对不起用户名、密码必须填写p Response.Writea hreflogin.
asp重填/a Response.End end if 下面将注册用户名逐条与数据库是记录的用户名对比。
如果数据库中已经有了提示用户不能再注册。
do while not rs.Eof irsuser_name if trima1trimithen Response.Write用户名重名p Response.Writea hreflogin.
asp重填/a Response.End end if rs.movenext loop 下面是检查密码与确认密码是否相同 if a2 b2 then Response.Write密码确认不正确p Response.Writea hreflogin.
asp重填/a Response.End end if 下面是将注册信息添加到数据库中。
利用encrypt加密用户密码。
c2encrypta2 strsqlinsert into useruser_namepasswordsexlovecareerintroductionsubmit_dateValuesa1a2a3a4a5a6now db.Executestrsql /h2 h2 aligncenter Response.Write注册成功p请记牢用户名和密码 /h2 paligncenterclassbase-4/p table width121height35border0aligncentercellpadding0cellspacing0 tr alignmiddle td script languageJavaScript function shutwin window.close return /script ahrefjavascriptshutwin关闭本窗口/a/td /tr /table paligncenter/p /body /html 2.6加密、还原密码的Function过程网页-security.
asp function decryptdcode dim texts dim i for i1 to lendcode textstextschrascmiddcodei2-i next decrypttexts end function function encryptecode Dim texts dim i for i1 to lenecode textstextschrascmidecodei2i next encrypttexts end function 3数据库文件 Access数据库文件-maindata.mdb 提示有人说为了安全将扩展名mdb改为asa或者
asp我个人不这样建议那更不安全。
数据库中存放一张名为user的表。
表的结构为包含8个字段 ID自动编号数值 user_name文本存放用户名 password文本存放密码 sex文本存放性别 love文本存放爱好 career文本存放职业 introduction文本存放兴趣 submit_date日期/时间存放注册时间由程序自动获取服务器日期时间。