Registration page Implementation Activation mailbox verification (asp.net C #) _ Practical Tips

Source: Internet
Author: User
Tags fdf account security mailmessage smtpclient
-----------Registration page Front Desk
Copy Code code as follows:

<%@ Page language= "C #" autoeventwireup= "true" codebehind= "Registe.aspx.cs" inherits= "csdn blog. Registe"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<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;
}
/* Head CSS style * *
#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;
}
/* Head CSS style End * *
/* Information Section start * *
#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;
}
/* Information part of the end * *
/* Bottom Start * *
#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;
}
/* Bottom End * *
</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 >= && 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>
<body>
<form id= "Form1" runat= "Server" >
<!--content-->
<div>
<!--head-->
<div id= "Head" >
<!--head left-->
<div id= "Lefthead" >
<a href= "http://www.csdn.net/" class= "ahead" > Home </a>
<a href= "http://news.csdn.net/" class= "ahead" > Industry </a>
<a href= "http://mobile.csdn.net/" class= "ahead" > Mobile </a>
<a href= "http://cloud.csdn.net/" class= "ahead" > Cloud computing </a>
<a href= "http://sd.csdn.net/" class= "ahead" > R </a>
<a href= "http://bbs.csdn.net/" class= "ahead" > Forum </a>
<a href= "http://blog.csdn.net/" class= "ahead" > blog </a>
<a href= "http://download.csdn.net/" class= "ahead" > Download </a>
<a class= "Ahead" > more </a>
</div>
<!--head Right-->
<div id= "Righthead" >
<span class= "Zhuyi" > You have not landed! </span>|
<a href= "http://www.csdn.net/" class= "ahead" > Login </a> |
<a href= "http://www.csdn.net/" class= "ahead" > Registration </a> |
<a href= "Https://passport.csdn.net/help/faq" class= "ahead" > Help </a>
</div>
</div>
<!--head end-->
<!--body-->
<div id= "Body" >
<!--pictures-->
<div id= "Picture" >

</div>
<!--information-->
<div id= "Xinxi" >
<div id= "Biaoti" >

</div>
<div id= "Xian" >

</div>
<div id= "Table" >
<table>
<!--user name-->
<tr>
<td><span class= "Zhuyi" >*</span> username:</td>
<td>
<asp:textbox id= "txtname" runat= "Server" controltovalidate= "TextBox1" ></asp:TextBox></td>
&LT;TD >
<asp:requiredfieldvalidator id= "RequiredFieldValidator1" runat= "Server"
Errormessage= "User name cannot be empty" controltovalidate= "txtname" display= "Dynamic"
Font-size= "15px" forecolor= "Red" ></asp:RequiredFieldValidator>
</td>
</tr>
&LT;TR&GT;&LT;TD&GT;&LT;/TD&GT;&LT;TD colspan= "2" >
<label style= "color: #c0c0c0; font-size:small;" > (Letters, numbers, or underline combinations.) ) </label></td></tr>
<!--password-->
<tr>
<td><span class= "Zhuyi" >*</span> password:</td>
<td>
<asp:textbox id= "Txtpassword" runat= "Server" ></asp:TextBox></td>
<td>
<asp:requiredfieldvalidator id= "RequiredFieldValidator2" runat= "Server"
Controltovalidate= "Txtpassword" display= "Dynamic" errormessage= "cannot be empty"
Font-size= "15px" forecolor= "Red" ></asp:RequiredFieldValidator>
<div><ul id= "Pwd-strong" style= "Display:none;" ><li> Weak </li><li> medium </li><li> strong </li></ul></div></td>
</tr>
&LT;TR&GT;&LT;TD&GT;&LT;/TD&GT;&LT;TD colspan= "2" >
<label style= "color: #c0c0c0; font-size:small;" > (For your account security, it is strongly recommended that your password use a number of different combinations of characters + numbers, and that the password length is greater than 5 digits.) ) </label></td></tr>
<!--Enter password again-->
<tr>
<td><span class= "Zhuyi" >*</span> Enter password again:</td>
<td>
<asp:textbox id= "Txtpasswordagain" runat= "Server" ></asp:TextBox></td>
<td>
<asp:requiredfieldvalidator id= "RequiredFieldValidator3" runat= "Server"
Controltovalidate= "Txtpassword" display= "Dynamic" errormessage= "cannot be empty"
Forecolor= "Red" font-size= "15px" ></asp:RequiredFieldValidator>
<asp:comparevalidator id= "CompareValidator1" runat= "Server"
errormessage= "Two input passwords inconsistent" controltocompare= "Txtpassword"
Controltovalidate= "Txtpasswordagain" display= "Dynamic" forecolor= "Red"
Font-size= "15px" ></asp:CompareValidator></td>
</tr>
&LT;TR&GT;&LT;TD&GT;&LT;/TD&GT;&LT;TD colspan= "2" >
<label style= "color: #c0c0c0; font-size:small;" > (Make sure your password is correct) </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= "cannot be empty"
Forecolor= "Red" font-size= "15px" ></asp:RequiredFieldValidator>
<asp:regularexpressionvalidator id= "RegularExpressionValidator1" runat= "Server"
Controltovalidate= "Txtemail" display= "Dynamic" errormessage= "Mailbox format is incorrect"
Validationexpression= "\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) * "
Forecolor= "Red" font-size= "15px" ></asp:RegularExpressionValidator>
</td>
</tr>
&LT;TR&GT;&LT;TD&GT;&LT;/TD&GT;&LT;TD colspan= "2" >
<label style= "color: #c0c0c0; font-size:small;" > (please fill in your usual email) </label></td></tr>
<!--verification Code-->
<tr>
<td><span class= "Zhuyi" >*</span> check code:</td>
<td>
<asp:textbox id= "TEXTBOX5" runat= "Server" ></asp:TextBox></td>
<td>
<asp:requiredfieldvalidator id= "RequiredFieldValidator5" runat= "Server"
Controltovalidate= "TextBox5" display= "Dynamic" errormessage= "cannot be empty" ></asp:RequiredFieldValidator>
</td>
</tr>
&LT;TR&GT;&LT;TD&GT;&LT;/TD&GT;&LT;TD colspan= "2" >
<span class= "Zhuyi" > (If you do not enter the authentication code continuously, check that your browser has disabled cookies.) <a href= "Http://passport.csdn.net/help/faq" > How to Enable cookies? </a>) </span></td></tr>
<tr>
<!--terms-->
<td><span class= "Zhuyi" >*</span> Registration terms:</td>
&LT;TD colspan= "2" >
<asp:checkbox id= "CheckBox1" runat= "Server"
Oncheckedchanged= "checkbox1_checkedchanged" text= "I have read and accepted"/><a href= "http://passport.csdn.net/help/terms "&GT;CSDN Registration terms </a>. </td>
</tr>
<!--registration Submission-->
<tr><td></td><td></td></tr>
<tr><td></td><td></td></tr>
<tr>
<td></td>
&LT;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>
<!--body End-->
<!--bottom-->
<div id= "footer" align= "Center" >
<div class= "Buttom" >
<a href= "http://www.csdn.net/company/about.html" class= "Abuttom" > Company Profile </a>|
<a href= "http://www.csdn.net/company/recruit.html" class= "Abuttom" > Careers </a>|
<a href= "http://www.csdn.net/company/marketing.html" class= "Abuttom" > Advertising service </a>|
<a href= "http://www.csdn.net/company/account.html" class= "Abuttom" > Bank Remittance account </a>|
<a href= "http://www.csdn.net/company/contact.html" class= "Abuttom" > Contact Way </a>|
<a href= "http://www.csdn.net/company/statement.html" class= "abuttom" > Copyright Notice </a>|
<a href= "http://www.csdn.net/company/layer.html" class= "Abuttom" > Legal advisor </a>|
<a href= "" class= "Abuttom" > Problem report </a>
</div>
<p class= "Buttom" > &AMP;NBSPICP &nbsp Certificate &nbsp070598 &nbsp No. </p>
<p class= "Buttom" > Beijing Innovation Information Technology Co., Ltd. &AMP;NBSP all rights reserved </p>
<p class= "Buttom" > Contact mailbox: Webmaster (at) csdn.net</p>
<p class= "Buttom" >Copyright©&nbsp1999-2012,&nbspCSDN.NET,&nbspAll&nbspRights& Nbspreserved</p>
<div>
<a href= "http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010" class= "Abuttom" ></a>
<a href= "https://trustsealinfo.verisign.com/splash?form_file=fdf/splash.fdf&dn=passport.csdn.net& LANG=ZH_CN "class=" Abuttom "></a>"
</div>

------Registration Page Background
Copy Code code as follows:

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 Blog
{
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 = "Please activate registration";
int number = Number1 ();
StringBuilder Contentbuilder = new StringBuilder ();
Contentbuilder.append ("Please click the link below to complete activation");
Contentbuilder.append ("<a href= ' http://localhost:15464/cheng.aspx?activecode=" + Activecode + "&id=" + number + "' > Activation </a>");
Mailmsg.body = Contentbuilder.tostring ();//concatenation string
Mailmsg.isbodyhtml = true;
SmtpClient client = new SmtpClient ();
Sender server Address
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 blog. Bll.t_user count = new BLL. T_user ();
int a = count. GetRecordCount ("");
return A;
}
protected void Imagebutton1_click (object sender, ImageClickEventArgs e)
{
CSDN blog. 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;//Generate Activation code
CSDN blog. Bll.t_user buser = new BLL. T_user ();
if (buser. ADD (Muser) > 0)
{
SendMail (Txtemail.text, Activecode)//email to registered users
Lbinfo. Text = "Save Success";
}
else {lbinfo. Text = "Save Failed"; }
}
}
}
</div>
<!--bottom end-->
</div>
</form>
</body>

------------Activation Validation
Copy Code code as follows:

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 Blog
{
public partial class Cheng:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
Remove parameter ID
int id = Convert.ToInt32 (request["id"]);
String activecode = request["Activecode"]. ToString ();
2 determine if a record with ID ID is present
Connecting to a database
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)
{
If the user exists to remove the Activecode field for comparison. If the same, modify the active field to True
Connecting to a database
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 ("Activation successful!<a href= ' denglu.aspx ' > Return login </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 ("The user already exists, but the activation code is wrong!") ");
}
}
Else
{
Response.Write ("The user does not exist, has not registered successfully!") ");
}
}
}
}

Achieve the following effects:
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.