注册页实现激活邮箱验证(asp.net c#)_asp.net教程-查字典教程网
注册页实现激活邮箱验证(asp.net c#)
注册页实现激活邮箱验证(asp.net c#)
发布时间:2017-01-07 来源:查字典编辑
摘要:-----------注册页前台复制代码代码如下:.zhuyi{color:Red;font-size:small;}#pwd-strong...

-----------注册页前台

复制代码 代码如下:

<%@ 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/">首页</a>

<a href="http://news.csdn.net/">业界</a>

<a href="http://mobile.csdn.net/">移动</a>

<a href="http://cloud.csdn.net/">云计算</a>

<a href="http://sd.csdn.net/">研发</a>

<a href="http://bbs.csdn.net/">论坛</a>

<a href="http://blog.csdn.net/">博客</a>

<a href="http://download.csdn.net/">下载</a>

<a>更多</a>

</div>

<>

<div id="righthead">

<span>你还未登陆!</span>| 

<a href="http://www.csdn.net/">登陆</a>  | 

<a href="http://www.csdn.net/">注册</a>  | 

<a href="https://passport.csdn.net/help/faq">帮助</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>*</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>(字母、数字或下划线组合。)</label></td></tr>

<>

<tr>

<td><span>*</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"><li>弱</li><li>中</li><li>强</li></ul></div></td>

</tr>

<tr><td></td><td colspan="2">

<label>(为了您的帐户安全,强烈建议您的密码使用字符+数字等多种不同类型的组合,并且密码长度大于5位。)</label></td></tr>

<>

<tr>

<td><span>*</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>(请确保密码正确)</label></td></tr>

<>

<tr>

<td><span>*</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>(请填写您常用的邮箱)</label></td></tr>

<>

<tr>

<td><span>*</span>校验码:</td>

<td>

<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox></td>

<td>

<img src="checkCode.aspx" />图片看不清?点击重新得到验证码

<asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"

ControlToValidate="TextBox5" Display="Dynamic" ErrorMessage="不能为空"></asp:RequiredFieldValidator>

</td>

</tr>

<tr><td></td><td colspan="2">

<span>(如您连续输入不对验证码,请检查您的浏览器是否禁用了Cookie。<a href="http://passport.csdn.net/help/faq">如何启用Cookie?</a>)</span></td></tr>

<tr>

<>

<td><span>*</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" />

<asp:Label ID="lbinfo" runat="server" ForeColor="Red"></asp:Label>

</td>

</tr>

</table>

<div>

</div>

</div>

</div>

</div>

<>

<>

<div id="footer" align="center">

<div>

<a href="http://www.csdn.net/company/about.html">公司简介</a>|

<a href="http://www.csdn.net/company/recruit.html" >招贤纳士</a>|

<a href="http://www.csdn.net/company/marketing.html">广告服务</a>|

<a href="http://www.csdn.net/company/account.html">银行汇款账号</a>|

<a href="http://www.csdn.net/company/contact.html">联系方式</a>|

<a href="http://www.csdn.net/company/statement.html">版权声明</a>|

<a href="http://www.csdn.net/company/layer.html">法律顾问</a>|

<a href="">问题报告</a>

</div>

<p>京  ICP  证  070598  号</p>

<p>北京创新乐知信息技术有限公司  版权所有</p>

<p><img src="images/zhuce4.gif" />联系邮箱:webmaster(at)csdn.net</p>

<p>Copyright © 1999-2012, CSDN.NET, All Rights Reserved</p>

<div>

<a href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><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"><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-PCSQLEXPRESSPC;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("用户不存在,还没注册成功!");

}

}

}

}

实现如下效果:

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新asp.net教程学习
    热门asp.net教程学习
    编程开发子分类