注册页实现激活邮箱验证(asp.net c#)
程序员文章站
2024-03-01 20:55:16
-----------注册页前台 复制代码 代码如下: <%@ page language="c#" autoeventwireup="true" codebehin...
-----------注册页前台
<%@ page language="c#" autoeventwireup="true" codebehind="registe.aspx.cs" inherits="csdn博客.registe" %>
<!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 runat="server">
<title></title>
<style type="text/css">
.zhuyi
{
color:red;
font-size:small;
}
#pwd-strong {
float: left;
margin: 0px;
padding: 0px;
list-style: none;
background-image: url(images/pwdstrong.gif);
background-repeat: no-repeat;
}
#pwd-strong li {
float: left;
padding: 0px;
color: #ccc;
font-size: 11px;
width: 64px;
height: 10px;
text-align: center;
padding-top: 9px;
}
.pwds3 {
background-position: -20px -70px;
}
.pwds2 {
background-position: -20px -44px;
}
.pwds1 {
background-position: -20px -18px;
}
#pwd-strong li.currs {
color: #000;
}
/*头部css样式*/
#head
{
margin:0;
}
#head a:hover
{
color:red;
}
.ahead
{
color:black;
font-size:small;
text-decoration:none;
}
#lefthead
{
float:left;
margin:0;
}
#righthead
{
float:right;
margin:0;
}
/*头部css样式结束*/
/*信息部分开始*/
#body
{
/*
border: 1px solid black;
*/
position:absolute;
width:900px;
height:700px;
left:230px;
top:50px;
}
#picture
{
float:left;
}
#xinxi
{
border:1px solid pink;
width:850px;
height:440px;
position:absolute;
left:20px;
top:50px
}
#biaoti
{
position:absolute;
left:1px;
top:10px;
}
#xian
{
position:absolute;
left:20px;
top:50px;
}
#table
{
position:absolute;
/*
border:1px solid black;
*/
left:50px;
top:90px;
}
/*信息部分结束*/
/*底部开始*/
#footer
{
/*
border:1px solid black;
*/
position:absolute;
left:430px;
top:560px;
}
.buttom
{
margin:0px;
font-size:small;
}
.abuttom
{
text-decoration:none;
color:black;
}
#footer a:hover
{
color:blue;
}
img
{
border:0px;
}
/*底部结束*/
</style>
<script src="emailvalidatorjs.js" type="text/javascript"></script>
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#txtpassword').keyup(function () {
var score = testpass($(this).val());
if (score < 34) {
$('#pwd-strong').css('display', 'block');
$('#pwd-strong').addclass('pwds1');
$('li:first').addclass('currs');
}
else if (score >= 34 && score < 68) {
$('#pwd-strong').css('display', 'block');
$('#pwd-strong').removeclass();
$('#pwd-strong').addclass('pwds2');
$('li:eq(1)').addclass('currs');
}
else {
$('#pwd-strong').css('display', 'block');
$('#pwd-strong').removeclass();
$('#pwd-strong').addclass('pwds3');
$('li:last').addclass('currs');
}
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<!--内容-->
<div>
<!--头部-->
<div id="head">
<!--头部左-->
<div id="lefthead">
<a href="http://www.csdn.net/" class="ahead">首页</a>
<a href="http://news.csdn.net/" class="ahead">业界</a>
<a href="http://mobile.csdn.net/" class="ahead">移动</a>
<a href="http://cloud.csdn.net/" class="ahead">云计算</a>
<a href="http://sd.csdn.net/" class="ahead">研发</a>
<a href="http://bbs.csdn.net/" class="ahead">论坛</a>
<a href="http://blog.csdn.net/" class="ahead">博客</a>
<a href="http://download.csdn.net/" class="ahead">下载</a>
<a class="ahead">更多</a>
</div>
<!--头部右-->
<div id="righthead">
<span class="zhuyi">你还未登陆!</span>| 
<a href="http://www.csdn.net/" class="ahead">登陆</a>  | 
<a href="http://www.csdn.net/" class="ahead">注册</a>  | 
<a href="https://passport.csdn.net/help/faq" class="ahead">帮助</a>
</div>
</div>
<!--头部结束-->
<!--身体-->
<div id="body" >
<!--图片-->
<div id="picture">
<img src="images/zhuce.gif" />
</div>
<!--信息-->
<div id="xinxi">
<div id="biaoti">
<img src="images/zhuce1.gif"/>
</div>
<div id="xian">
<img src="images/zhuce2.png" />
</div>
<div id="table">
<table>
<!--用户名-->
<tr>
<td><span class="zhuyi">*</span>用户名:</td>
<td>
<asp:textbox id="txtname" runat="server" controltovalidate="textbox1"></asp:textbox></td>
<td >
<asp:requiredfieldvalidator id="requiredfieldvalidator1" runat="server"
errormessage="用户名不能为空" controltovalidate="txtname" display="dynamic"
font-size="15px" forecolor="red"></asp:requiredfieldvalidator>
</td>
</tr>
<tr><td></td><td colspan="2">
<label style="color:#c0c0c0;font-size:small;">(字母、数字或下划线组合。)</label></td></tr>
<!--密码-->
<tr>
<td><span class="zhuyi">*</span>密码:</td>
<td>
<asp:textbox id="txtpassword" runat="server"></asp:textbox></td>
<td>
<asp:requiredfieldvalidator id="requiredfieldvalidator2" runat="server"
controltovalidate="txtpassword" display="dynamic" errormessage="不能为空"
font-size="15px" forecolor="red"></asp:requiredfieldvalidator>
<div><ul id="pwd-strong" style="display: none;"><li>弱</li><li>中</li><li>强</li></ul></div></td>
</tr>
<tr><td></td><td colspan="2">
<label style="color:#c0c0c0;font-size:small;">(为了您的帐户安全,强烈建议您的密码使用字符+数字等多种不同类型的组合,并且密码长度大于5位。)</label></td></tr>
<!--再次输入密码-->
<tr>
<td><span class="zhuyi">*</span>再次输入密码:</td>
<td>
<asp:textbox id="txtpasswordagain" runat="server"></asp:textbox></td>
<td>
<asp:requiredfieldvalidator id="requiredfieldvalidator3" runat="server"
controltovalidate="txtpassword" display="dynamic" errormessage="不能为空"
forecolor="red" font-size="15px"></asp:requiredfieldvalidator>
<asp:comparevalidator id="comparevalidator1" runat="server"
errormessage="两次输入的密码不一致" controltocompare="txtpassword"
controltovalidate="txtpasswordagain" display="dynamic" forecolor="red"
font-size="15px"></asp:comparevalidator></td>
</tr>
<tr><td></td><td colspan="2">
<label style="color:#c0c0c0;font-size:small;">(请确保密码正确)</label></td></tr>
<!--e-mail-->
<tr>
<td><span class="zhuyi">*</span>e-mail</td>
<td>
<asp:textbox id="txtemail" runat="server"></asp:textbox></td>
<td>
<asp:requiredfieldvalidator id="requiredfieldvalidator4" runat="server"
controltovalidate="txtemail" display="dynamic" errormessage="不能为空"
forecolor="red" font-size="15px"></asp:requiredfieldvalidator>
<asp:regularexpressionvalidator id="regularexpressionvalidator1" runat="server"
controltovalidate="txtemail" display="dynamic" errormessage="邮箱格式不正确"
validationexpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
forecolor="red" font-size="15px"></asp:regularexpressionvalidator>
</td>
</tr>
<tr><td></td><td colspan="2">
<label style="color:#c0c0c0;font-size:small;">(请填写您常用的邮箱)</label></td></tr>
<!--验证码-->
<tr>
<td><span class="zhuyi">*</span>校验码:</td>
<td>
<asp:textbox id="textbox5" runat="server"></asp:textbox></td>
<td>
<img src="checkcode.aspx" onclick="this.src='checkcode.aspx?aaa='+new date()" alt="" />图片看不清?点击重新得到验证码
<asp:requiredfieldvalidator id="requiredfieldvalidator5" runat="server"
controltovalidate="textbox5" display="dynamic" errormessage="不能为空"></asp:requiredfieldvalidator>
</td>
</tr>
<tr><td></td><td colspan="2">
<span class="zhuyi">(如您连续输入不对验证码,请检查您的浏览器是否禁用了cookie。<a href="http://passport.csdn.net/help/faq">如何启用cookie?</a>)</span></td></tr>
<tr>
<!--条款-->
<td><span class="zhuyi">*</span>注册条款:</td>
<td colspan="2">
<asp:checkbox id="checkbox1" runat="server"
oncheckedchanged="checkbox1_checkedchanged" text="我已仔细阅读并接受" /><a href="http://passport.csdn.net/help/terms">csdn注册条款</a>。</td>
</tr>
<!--注册提交-->
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
<tr>
<td></td>
<td colspan="2">
<asp:imagebutton id="imagebutton1" runat="server"
imageurl="~/images/zhuce.jpg" onclick="imagebutton1_click" />
<asp:label id="lbinfo" runat="server" forecolor="red"></asp:label>
</td>
</tr>
</table>
<div>
</div>
</div>
</div>
</div>
<!--身体结束-->
<!--底部-->
<div id="footer" align="center">
<div class="buttom">
<a href="http://www.csdn.net/company/about.html" class="abuttom">公司简介</a>|
<a href="http://www.csdn.net/company/recruit.html" class="abuttom" >招贤纳士</a>|
<a href="http://www.csdn.net/company/marketing.html" class="abuttom">广告服务</a>|
<a href="http://www.csdn.net/company/account.html" class="abuttom">银行汇款账号</a>|
<a href="http://www.csdn.net/company/contact.html" class="abuttom">联系方式</a>|
<a href="http://www.csdn.net/company/statement.html" class="abuttom">版权声明</a>|
<a href="http://www.csdn.net/company/layer.html" class="abuttom">法律顾问</a>|
<a href="" class="abuttom">问题报告</a>
</div>
<p class="buttom">京  icp  证  070598  号</p>
<p class="buttom">北京创新乐知信息技术有限公司  版权所有</p>
<p class="buttom"><img src="images/zhuce4.gif" />联系邮箱:webmaster(at)csdn.net</p>
<p class="buttom">copyright © 1999-2012, csdn.net, all rights reserved</p>
<div>
<a href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010" class="abuttom"><img src="images/denglu2.gif"/></a>
<a href="https://trustsealinfo.verisign.com/splash?form_file=fdf/splash.fdf&dn=passport.csdn.net&lang=zh_cn" class="abuttom"><img src="images/denglu1.gif"/></a>
</div>
------注册页后台
using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
using system.text;
using system.net.mail;
using system.net;
using system.data.sqlclient;
namespace csdn博客
{
public partial class registe : system.web.ui.page
{
protected void page_load(object sender, eventargs e)
{
}
protected void checkbox1_checkedchanged(object sender, eventargs e)
{
}
public void sendmail(string email, string activecode)
{
mailmessage mailmsg = new mailmessage();
mailmsg.from = new mailaddress("15031259715@163.com");
mailmsg.to.add(email);
mailmsg.subject = "请激活注册";
int number = number1();
stringbuilder contentbuilder = new stringbuilder();
contentbuilder.append("请单击以下链接完成激活");
contentbuilder.append("<a href='http://localhost:15464/cheng.aspx?activecode=" + activecode + "&id=" + number + "'>激活</a>");
mailmsg.body = contentbuilder.tostring();//拼接字符串
mailmsg.isbodyhtml = true;
smtpclient client = new smtpclient();
//发件方服务器地址
client.host = "smtp.163.com";
client.port = 25;
//mailmsg.isbodyhtml = true;
networkcredential credetial = new networkcredential();
credetial.username = "15031259715";
credetial.password = "wangjing911214++";
client.credentials = credetial;
client.send(mailmsg);
}
public int number1()
{
csdn博客.bll.t_user count = new bll.t_user();
int a = count.getrecordcount("");
return a;
}
protected void imagebutton1_click(object sender, imageclickeventargs e)
{
csdn博客.model.t_user muser = new model.t_user();
muser.name = txtname.text;
muser.password = txtpassword.text;
muser.e_mail = txtemail.text;
string activecode=guid.newguid().tostring().substring(0, 8);
muser.activecode = activecode;//生成激活码
csdn博客.bll.t_user buser = new bll.t_user();
if (buser.add(muser) > 0)
{
sendmail(txtemail.text, activecode);//给注册用户发邮件
lbinfo.text = "保存成功";
}
else { lbinfo.text = "保存失败"; }
}
}
}
</div>
<!--底部结束-->
</div>
</form>
</body>
</html>
------------激活验证
using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
using system.data.sqlclient;
namespace csdn博客
{
public partial class cheng : system.web.ui.page
{
protected void page_load(object sender, eventargs e)
{
//取出参数id
int id = convert.toint32(request["id"]);
string activecode = request["activecode"].tostring();
//2判断id为id的记录是否存在
//连接数据库
string constr = "data source=love-pc\\sqlexpresspc;initial catalog=blogs;user id=sa;password=admin";
int number;
using (sqlconnection con = new sqlconnection(constr))
{
string sql = "select count(*) from t_user where id=@id";
using (sqlcommand cmd = new sqlcommand(sql, con))
{
con.open();
cmd.parameters.addwithvalue("@id", id);
number = convert.toint32(cmd.executescalar());
}
}
if (number > 0)
{
//如果该用户存在取出activecode字段进行比较。如果一样,把active字段修改为true
//连接数据库
string ac;
using (sqlconnection con = new sqlconnection(constr))
{
string sql = "select activecode from t_user where id=@id";
using (sqlcommand cmd = new sqlcommand(sql, con))
{
con.open();
cmd.parameters.addwithvalue("@id", id);
ac = cmd.executescalar().tostring(); ;
}
}
if (activecode == ac)
{
response.write("激活成功!<a href='denglu.aspx'>返回登录</a>");
using (sqlconnection con = new sqlconnection(constr))
{
string sql = "update t_user set active=1 where id=@id";
using (sqlcommand cmd = new sqlcommand(sql, con))
{
con.open();
cmd.parameters.addwithvalue("@id", id);
number = convert.toint32(cmd.executescalar());
}
}
}
else
{
response.write("用户已存在,但是激活码错误!");
}
}
else
{
response.write("用户不存在,还没注册成功!");
}
}
}
}
实现如下效果:
复制代码 代码如下:
<%@ page language="c#" autoeventwireup="true" codebehind="registe.aspx.cs" inherits="csdn博客.registe" %>
<!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 runat="server">
<title></title>
<style type="text/css">
.zhuyi
{
color:red;
font-size:small;
}
#pwd-strong {
float: left;
margin: 0px;
padding: 0px;
list-style: none;
background-image: url(images/pwdstrong.gif);
background-repeat: no-repeat;
}
#pwd-strong li {
float: left;
padding: 0px;
color: #ccc;
font-size: 11px;
width: 64px;
height: 10px;
text-align: center;
padding-top: 9px;
}
.pwds3 {
background-position: -20px -70px;
}
.pwds2 {
background-position: -20px -44px;
}
.pwds1 {
background-position: -20px -18px;
}
#pwd-strong li.currs {
color: #000;
}
/*头部css样式*/
#head
{
margin:0;
}
#head a:hover
{
color:red;
}
.ahead
{
color:black;
font-size:small;
text-decoration:none;
}
#lefthead
{
float:left;
margin:0;
}
#righthead
{
float:right;
margin:0;
}
/*头部css样式结束*/
/*信息部分开始*/
#body
{
/*
border: 1px solid black;
*/
position:absolute;
width:900px;
height:700px;
left:230px;
top:50px;
}
#picture
{
float:left;
}
#xinxi
{
border:1px solid pink;
width:850px;
height:440px;
position:absolute;
left:20px;
top:50px
}
#biaoti
{
position:absolute;
left:1px;
top:10px;
}
#xian
{
position:absolute;
left:20px;
top:50px;
}
#table
{
position:absolute;
/*
border:1px solid black;
*/
left:50px;
top:90px;
}
/*信息部分结束*/
/*底部开始*/
#footer
{
/*
border:1px solid black;
*/
position:absolute;
left:430px;
top:560px;
}
.buttom
{
margin:0px;
font-size:small;
}
.abuttom
{
text-decoration:none;
color:black;
}
#footer a:hover
{
color:blue;
}
img
{
border:0px;
}
/*底部结束*/
</style>
<script src="emailvalidatorjs.js" type="text/javascript"></script>
<script src="jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('#txtpassword').keyup(function () {
var score = testpass($(this).val());
if (score < 34) {
$('#pwd-strong').css('display', 'block');
$('#pwd-strong').addclass('pwds1');
$('li:first').addclass('currs');
}
else if (score >= 34 && score < 68) {
$('#pwd-strong').css('display', 'block');
$('#pwd-strong').removeclass();
$('#pwd-strong').addclass('pwds2');
$('li:eq(1)').addclass('currs');
}
else {
$('#pwd-strong').css('display', 'block');
$('#pwd-strong').removeclass();
$('#pwd-strong').addclass('pwds3');
$('li:last').addclass('currs');
}
})
})
</script>
</head>
<body>
<form id="form1" runat="server">
<!--内容-->
<div>
<!--头部-->
<div id="head">
<!--头部左-->
<div id="lefthead">
<a href="http://www.csdn.net/" class="ahead">首页</a>
<a href="http://news.csdn.net/" class="ahead">业界</a>
<a href="http://mobile.csdn.net/" class="ahead">移动</a>
<a href="http://cloud.csdn.net/" class="ahead">云计算</a>
<a href="http://sd.csdn.net/" class="ahead">研发</a>
<a href="http://bbs.csdn.net/" class="ahead">论坛</a>
<a href="http://blog.csdn.net/" class="ahead">博客</a>
<a href="http://download.csdn.net/" class="ahead">下载</a>
<a class="ahead">更多</a>
</div>
<!--头部右-->
<div id="righthead">
<span class="zhuyi">你还未登陆!</span>| 
<a href="http://www.csdn.net/" class="ahead">登陆</a>  | 
<a href="http://www.csdn.net/" class="ahead">注册</a>  | 
<a href="https://passport.csdn.net/help/faq" class="ahead">帮助</a>
</div>
</div>
<!--头部结束-->
<!--身体-->
<div id="body" >
<!--图片-->
<div id="picture">
<img src="images/zhuce.gif" />
</div>
<!--信息-->
<div id="xinxi">
<div id="biaoti">
<img src="images/zhuce1.gif"/>
</div>
<div id="xian">
<img src="images/zhuce2.png" />
</div>
<div id="table">
<table>
<!--用户名-->
<tr>
<td><span class="zhuyi">*</span>用户名:</td>
<td>
<asp:textbox id="txtname" runat="server" controltovalidate="textbox1"></asp:textbox></td>
<td >
<asp:requiredfieldvalidator id="requiredfieldvalidator1" runat="server"
errormessage="用户名不能为空" controltovalidate="txtname" display="dynamic"
font-size="15px" forecolor="red"></asp:requiredfieldvalidator>
</td>
</tr>
<tr><td></td><td colspan="2">
<label style="color:#c0c0c0;font-size:small;">(字母、数字或下划线组合。)</label></td></tr>
<!--密码-->
<tr>
<td><span class="zhuyi">*</span>密码:</td>
<td>
<asp:textbox id="txtpassword" runat="server"></asp:textbox></td>
<td>
<asp:requiredfieldvalidator id="requiredfieldvalidator2" runat="server"
controltovalidate="txtpassword" display="dynamic" errormessage="不能为空"
font-size="15px" forecolor="red"></asp:requiredfieldvalidator>
<div><ul id="pwd-strong" style="display: none;"><li>弱</li><li>中</li><li>强</li></ul></div></td>
</tr>
<tr><td></td><td colspan="2">
<label style="color:#c0c0c0;font-size:small;">(为了您的帐户安全,强烈建议您的密码使用字符+数字等多种不同类型的组合,并且密码长度大于5位。)</label></td></tr>
<!--再次输入密码-->
<tr>
<td><span class="zhuyi">*</span>再次输入密码:</td>
<td>
<asp:textbox id="txtpasswordagain" runat="server"></asp:textbox></td>
<td>
<asp:requiredfieldvalidator id="requiredfieldvalidator3" runat="server"
controltovalidate="txtpassword" display="dynamic" errormessage="不能为空"
forecolor="red" font-size="15px"></asp:requiredfieldvalidator>
<asp:comparevalidator id="comparevalidator1" runat="server"
errormessage="两次输入的密码不一致" controltocompare="txtpassword"
controltovalidate="txtpasswordagain" display="dynamic" forecolor="red"
font-size="15px"></asp:comparevalidator></td>
</tr>
<tr><td></td><td colspan="2">
<label style="color:#c0c0c0;font-size:small;">(请确保密码正确)</label></td></tr>
<!--e-mail-->
<tr>
<td><span class="zhuyi">*</span>e-mail</td>
<td>
<asp:textbox id="txtemail" runat="server"></asp:textbox></td>
<td>
<asp:requiredfieldvalidator id="requiredfieldvalidator4" runat="server"
controltovalidate="txtemail" display="dynamic" errormessage="不能为空"
forecolor="red" font-size="15px"></asp:requiredfieldvalidator>
<asp:regularexpressionvalidator id="regularexpressionvalidator1" runat="server"
controltovalidate="txtemail" display="dynamic" errormessage="邮箱格式不正确"
validationexpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
forecolor="red" font-size="15px"></asp:regularexpressionvalidator>
</td>
</tr>
<tr><td></td><td colspan="2">
<label style="color:#c0c0c0;font-size:small;">(请填写您常用的邮箱)</label></td></tr>
<!--验证码-->
<tr>
<td><span class="zhuyi">*</span>校验码:</td>
<td>
<asp:textbox id="textbox5" runat="server"></asp:textbox></td>
<td>
<img src="checkcode.aspx" onclick="this.src='checkcode.aspx?aaa='+new date()" alt="" />图片看不清?点击重新得到验证码
<asp:requiredfieldvalidator id="requiredfieldvalidator5" runat="server"
controltovalidate="textbox5" display="dynamic" errormessage="不能为空"></asp:requiredfieldvalidator>
</td>
</tr>
<tr><td></td><td colspan="2">
<span class="zhuyi">(如您连续输入不对验证码,请检查您的浏览器是否禁用了cookie。<a href="http://passport.csdn.net/help/faq">如何启用cookie?</a>)</span></td></tr>
<tr>
<!--条款-->
<td><span class="zhuyi">*</span>注册条款:</td>
<td colspan="2">
<asp:checkbox id="checkbox1" runat="server"
oncheckedchanged="checkbox1_checkedchanged" text="我已仔细阅读并接受" /><a href="http://passport.csdn.net/help/terms">csdn注册条款</a>。</td>
</tr>
<!--注册提交-->
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
<tr>
<td></td>
<td colspan="2">
<asp:imagebutton id="imagebutton1" runat="server"
imageurl="~/images/zhuce.jpg" onclick="imagebutton1_click" />
<asp:label id="lbinfo" runat="server" forecolor="red"></asp:label>
</td>
</tr>
</table>
<div>
</div>
</div>
</div>
</div>
<!--身体结束-->
<!--底部-->
<div id="footer" align="center">
<div class="buttom">
<a href="http://www.csdn.net/company/about.html" class="abuttom">公司简介</a>|
<a href="http://www.csdn.net/company/recruit.html" class="abuttom" >招贤纳士</a>|
<a href="http://www.csdn.net/company/marketing.html" class="abuttom">广告服务</a>|
<a href="http://www.csdn.net/company/account.html" class="abuttom">银行汇款账号</a>|
<a href="http://www.csdn.net/company/contact.html" class="abuttom">联系方式</a>|
<a href="http://www.csdn.net/company/statement.html" class="abuttom">版权声明</a>|
<a href="http://www.csdn.net/company/layer.html" class="abuttom">法律顾问</a>|
<a href="" class="abuttom">问题报告</a>
</div>
<p class="buttom">京  icp  证  070598  号</p>
<p class="buttom">北京创新乐知信息技术有限公司  版权所有</p>
<p class="buttom"><img src="images/zhuce4.gif" />联系邮箱:webmaster(at)csdn.net</p>
<p class="buttom">copyright © 1999-2012, csdn.net, all rights reserved</p>
<div>
<a href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010" class="abuttom"><img src="images/denglu2.gif"/></a>
<a href="https://trustsealinfo.verisign.com/splash?form_file=fdf/splash.fdf&dn=passport.csdn.net&lang=zh_cn" class="abuttom"><img src="images/denglu1.gif"/></a>
</div>
------注册页后台
复制代码 代码如下:
using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
using system.text;
using system.net.mail;
using system.net;
using system.data.sqlclient;
namespace csdn博客
{
public partial class registe : system.web.ui.page
{
protected void page_load(object sender, eventargs e)
{
}
protected void checkbox1_checkedchanged(object sender, eventargs e)
{
}
public void sendmail(string email, string activecode)
{
mailmessage mailmsg = new mailmessage();
mailmsg.from = new mailaddress("15031259715@163.com");
mailmsg.to.add(email);
mailmsg.subject = "请激活注册";
int number = number1();
stringbuilder contentbuilder = new stringbuilder();
contentbuilder.append("请单击以下链接完成激活");
contentbuilder.append("<a href='http://localhost:15464/cheng.aspx?activecode=" + activecode + "&id=" + number + "'>激活</a>");
mailmsg.body = contentbuilder.tostring();//拼接字符串
mailmsg.isbodyhtml = true;
smtpclient client = new smtpclient();
//发件方服务器地址
client.host = "smtp.163.com";
client.port = 25;
//mailmsg.isbodyhtml = true;
networkcredential credetial = new networkcredential();
credetial.username = "15031259715";
credetial.password = "wangjing911214++";
client.credentials = credetial;
client.send(mailmsg);
}
public int number1()
{
csdn博客.bll.t_user count = new bll.t_user();
int a = count.getrecordcount("");
return a;
}
protected void imagebutton1_click(object sender, imageclickeventargs e)
{
csdn博客.model.t_user muser = new model.t_user();
muser.name = txtname.text;
muser.password = txtpassword.text;
muser.e_mail = txtemail.text;
string activecode=guid.newguid().tostring().substring(0, 8);
muser.activecode = activecode;//生成激活码
csdn博客.bll.t_user buser = new bll.t_user();
if (buser.add(muser) > 0)
{
sendmail(txtemail.text, activecode);//给注册用户发邮件
lbinfo.text = "保存成功";
}
else { lbinfo.text = "保存失败"; }
}
}
}
</div>
<!--底部结束-->
</div>
</form>
</body>
</html>
------------激活验证
复制代码 代码如下:
using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.ui;
using system.web.ui.webcontrols;
using system.data.sqlclient;
namespace csdn博客
{
public partial class cheng : system.web.ui.page
{
protected void page_load(object sender, eventargs e)
{
//取出参数id
int id = convert.toint32(request["id"]);
string activecode = request["activecode"].tostring();
//2判断id为id的记录是否存在
//连接数据库
string constr = "data source=love-pc\\sqlexpresspc;initial catalog=blogs;user id=sa;password=admin";
int number;
using (sqlconnection con = new sqlconnection(constr))
{
string sql = "select count(*) from t_user where id=@id";
using (sqlcommand cmd = new sqlcommand(sql, con))
{
con.open();
cmd.parameters.addwithvalue("@id", id);
number = convert.toint32(cmd.executescalar());
}
}
if (number > 0)
{
//如果该用户存在取出activecode字段进行比较。如果一样,把active字段修改为true
//连接数据库
string ac;
using (sqlconnection con = new sqlconnection(constr))
{
string sql = "select activecode from t_user where id=@id";
using (sqlcommand cmd = new sqlcommand(sql, con))
{
con.open();
cmd.parameters.addwithvalue("@id", id);
ac = cmd.executescalar().tostring(); ;
}
}
if (activecode == ac)
{
response.write("激活成功!<a href='denglu.aspx'>返回登录</a>");
using (sqlconnection con = new sqlconnection(constr))
{
string sql = "update t_user set active=1 where id=@id";
using (sqlcommand cmd = new sqlcommand(sql, con))
{
con.open();
cmd.parameters.addwithvalue("@id", id);
number = convert.toint32(cmd.executescalar());
}
}
}
else
{
response.write("用户已存在,但是激活码错误!");
}
}
else
{
response.write("用户不存在,还没注册成功!");
}
}
}
}
实现如下效果: