Register page to activate email verification (asp.net c #)

Source: Internet
Author: User
Tags fdf account security mailmessage smtpclient

----------- Registration page front-end Copy codeThe Code is 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">
<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;
}
/* Header 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;
}
/* End of the header css style */
/* Start the Information Section */
# 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: pixel PX;
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;
}
/* End part of information */
/* Start at the bottom */
# Footer
{
/*
Border: 1px solid black;
*/
Position: absolute;
Left: pixel PX;
Top: 560px;
}
. Buttom
{
Margin: 0px;
Font-size: small;
}
. Abuttom
{
Text-decoration: none;
Color: Black;
}
# Footer a: hover
{
Color: Blue;
}
Img
{
Border: 0px;
}
/* End at the bottom */
</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 ){
Certificate ('0000pwd-strong'0000.css ('display', 'block ');
$ ('# Pwd-strong'). addClass ('pwds1 ');
$ ('Li: first '). addClass ('currs ');
}
Else if (score >=34 & score <68 ){
Certificate ('0000pwd-strong'0000.css ('display', 'block ');
$ ('# Pwd-strong'). removeClass ();
$ ('# Pwd-strong'). addClass ('pwds2 ');
$ ('Li: eq (1) '). addClass ('currs ');
}
Else {
Certificate ('0000pwd-strong'0000.css ('display', 'block ');
$ ('# Pwd-strong'). removeClass ();
$ ('# Pwd-strong'). addClass ('pwds3 ');
$ ('Li: la'). addClass ('currs ');
}
})
})
</Script>
</Head>
<Body>
<Form id = "form1" runat = "server">
<! -- Content -->
<Div>
<! -- Header -->
<Div id = "head">
<! -- Header 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"> move </a>
<A href = "http://cloud.csdn.net/" class = "ahead"> cloud computing </a>
<A href = "http://sd.csdn.net/" class = "ahead"> R & D </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>
<! -- Right of the header -->
<Div id = "righthead">
<Span class = "zhuyi"> you have not logged on! </Span> | & nbsp
<A href = "http://www.csdn.net/" class = "ahead"> login </a> & nbsp | & nbsp
<A href = "http://www.csdn.net/" class = "ahead"> Registration </a> & nbsp | & nbsp
<A href = "https://passport.csdn.net/help/faq" class = "ahead"> help </a>
</Div>
</Div>
<! -- End of the header -->
<! -- Body -->
<Div id = "body">
<! -- Image -->
<Div id = "picture">

</Div>
<! -- Info -->
<Div id = "xinxi">
<Div id = "biaoti">

</Div>
<Div id = "xian">

</Div>
<Div id = "table">
<Table>
<! -- Username -->
<Tr>
<Td> <span class = "zhuyi"> * </span> User name: </td>
<Td>
<Asp: TextBox ID = "txtName" runat = "server" ControlToValidate = "TextBox1"> </asp: TextBox> </td>
<Td>
<Asp: RequiredFieldValidator ID = "RequiredFieldValidator1" runat = "server"
ErrorMessage = "username cannot be blank" 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;"> (combination of letters, numbers, and underscores .) </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 blank"
Font-Size = "15px" ForeColor = "Red"> </asp: RequiredFieldValidator>
<Div> <ul id = "pwd-strong" style = "display: none; "> <li> weak </li> <li> moderate </li> <li> strong </li> </ul> </div> </td>
</Tr>
<Tr> <td> </td> <td colspan = "2">
<Label style = "color: # c0c0c0; font-size: small;"> (for your account security, we strongly recommend that you use a combination of characters, numbers, and other types of passwords. The password length must be greater than 5 characters .) </Label> </td> </tr>
<! -- Enter the password again -->
<Tr>
<Td> <span class = "zhuyi"> * </span> enter the 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 blank"
ForeColor = "Red" Font-Size = "15px"> </asp: RequiredFieldValidator>
<Asp: CompareValidator ID = "CompareValidator1" runat = "server"
ErrorMessage = "the two passwords are inconsistent" 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;"> (ensure the password is correct) </label> </td> </tr>
<! -- E-mail -->
<Tr>
<Td> <span class = "zhuyi"> * </span> email </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 blank"
ForeColor = "Red" Font-Size = "15px"> </asp: RequiredFieldValidator>
<Asp: RegularExpressionValidator ID = "RegularExpressionValidator1" runat = "server"
ControlToValidate = "txtEmail" Display = "Dynamic" ErrorMessage = "Incorrect email format"
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;"> (enter your frequently used email address) </label> </td> </tr>
<! -- Verification code -->
<Tr>
<Td> <span class = "zhuyi"> * </span> Verification Code: </td>
<Td>
<Asp: TextBox ID = "TextBox5" runat = "server"> </asp: TextBox> </td>
<Td>
Can't you see the image clearly? Click to obtain the verification code again.
<Asp: RequiredFieldValidator ID = "RequiredFieldValidator5" runat = "server"
ControlToValidate = "TextBox5" Display = "Dynamic" ErrorMessage = "cannot be blank"> </asp: RequiredFieldValidator>
</Td>
</Tr>
<Tr> <td> </td> <td colspan = "2">
<Span class = "zhuyi"> (if you do not enter the Verification Code consecutively, check whether the Cookie is disabled in your browser. <A href = "http://passport.csdn.net/help/faq"> How do I Enable cookies? </A>) </span> </td> </tr>
<Tr>
<! -- Terms -->
<Td> <span class = "zhuyi"> * </span> terms of registration: </td>
<Td colspan = "2">
<Asp: CheckBox ID = "CheckBox1" runat = "server"
Oncheckedchanged = "checkbox#checkedchanged" Text = "I have carefully read and accept"/> <a href = "http://passport.csdn.net/help/terms"> CSDN registration terms </a>. </Td>
</Tr>
<! -- Submit registration -->
<Tr> <td> </tr>
<Tr> <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>
<! -- Physically ended -->
<! -- 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"> talent </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 Information </a> |
<A href = "http://www.csdn.net/company/statement.html" class = "abuttom"> copyright statement </a> |
<A href = "http://www.csdn.net/company/layer.html" class = "abuttom"> legal counsel </a> |
<A href = "" class = "abuttom"> problem report </a>
</Div>
<P class = "buttom"> Beijing & nbsp & nbspICP & nbsp Certificate & nbsp & nbsp070598 & nbsp No. </p>
<P class = "buttom"> Beijing innovation lezhi Information Technology Co., Ltd. & nbsp All Rights Reserved </p>
<P class = "buttom"> contact email: webmaster (at) csdn.net </p>
<P class = "buttom"> Copyright & nbsp & 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 backgroundCopy codeThe Code is 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 checkbox#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 = "Activate registration ";
Int number = number1 ();
StringBuilder contentBuilder = new StringBuilder ();
ContentBuilder. Append ("click the following link to complete activation ");
ContentBuilder. Append ("<a href = 'HTTP: // localhost: 15464/cheng. aspx? Activecode = "+ activeCode +" & id = "+ number +" '> activation </a> ");
MailMsg. Body = contentBuilder. ToString (); // concatenate a 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 = "wangjing938514 ++ ";
Client. Credentials = credetial;
Client. Send (mailMsg );
}
Public int number1 ()
{
CSDN blog. BLL. T_User count = new BLL. T_User ();
Int a = count. GetRecordCount ("");
Return;
}
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; // generates an activation code
CSDN blog. BLL. T_User buser = new BLL. T_User ();
If (buser. Add (muser)> 0)
{
SendMail (txtEmail. Text, activecode); // send an email to the registered user
Lbinfo. Text = "saved successfully ";
}
Else {lbinfo. Text = "failed to save ";}
}
}
}
</Div>
<! -- End at the bottom -->
</Div>
</Form>
</Body>
</Html>

------------ Activation VerificationCopy codeThe Code is 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)
{
// Retrieve the parameter id
Int id = Convert. ToInt32 (Request ["id"]);
String activeCode = Request ["activecode"]. ToString ();
// 2 determine whether a record with id as id exists
// Connect to the 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, retrieve the ActiveCode field for comparison. If the same, change the Active field to true.
// Connect to the 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 ("activated successfully! <A href = 'denglu. aspx '> return to logon </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 incorrect! ");
}
}
Else
{
Response. Write ("the user does not exist. It has not been registered successfully! ");
}
}
}
}

Achieve the following results:

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.