ASP. NET implements forgotten password recovery code

Source: Internet
Author: User

1 <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
2
3 4 5 <title> individual Member password recovery </title>
6 <link href= "/style.css" rel= "stylesheet" type= "Text/css"/>
7 <script language= "JavaScript" type= "Text/javascript" >
8//Check whether e-Mail has been registered
9 function Checkemail ()
10 {
each var e = document.getElementById ("email"). Value;
if (E! = "")
13 {
if (!/(\s) +[@]{1} (\s) +[.] {1} (\w) +/.test (e))
15 {
Alert ("Please enter a properly formatted e-mail address!") ");
+ var email = document.getElementById ("email");
Email.value = "";
Email.focus ();
20}
21}
22}
23
function Checkall ()
25 {
$ var ee = document.getElementById ("username"). Value;
if (ee = = "")
28 {
Alert (' Login name cannot be null ');
return false;
31}
32
var e = document.getElementById ("email"). Value;
if (E = = "")
35 {
Alert (' emial cannot be empty ');
The PNs return false;
38}
39
40
41}
42
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>
<table width= "778" border= "0" align= "center" cellpadding= "5" cellspacing= "0" class= "Table_huang" >
<tr>
&LT;TD colspan= "2" class= "Td_huang_14_write" > <span style= "font-size:11pt" >>> get password </span> </td>
Wuyi </tr>
<tr>
&LT;TD width= "></td>"
&LT;TD width= "724" ><table width= "90%" border= "0" cellspacing= "2" cellpadding= "5" >
<tr>
&LT;TD width= "23%" ><div align= "right" > User name:</div></td>
&LT;TD width= "77%" >
<asp:textbox id= "username" runat= "server" width= "150px" ></asp:TextBox></td>
</tr>
<tr>
<td><div align= "Right" > Registered email:</div></td>
<td>
<asp:textbox id= "Email" runat= "server" width= "200px" ></asp:TextBox></td>
</tr>
<tr>
<td><div align= "Right" > Verification Code:</div></td>
<td><table width= "100%" >
<tr>
&LT;TD align= "left" valign= "Top" style= "width:64px" ><asp:textbox id= "Txt_validcode" runat= "Server" Height= " 15px "width=" 62px "></asp:TextBox> </td>
&LT;TD align= "left" valign= "top" ></td>
</tr>
</table></td>
</tr>
<tr>
75
&LT;TD colspan= "2" style= "Text-align:center" >
<asp:button id= "Button1" runat= "Server" text= "Retrieve password"/></td>
</tr>
</table> </td>
</tr>
Bayi </table>
</div>
</form>
</body>

Back-end source code:

1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Collections;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.WebControls;
9 using System.Web.UI.WebControls.WebParts;
Ten using System.Web.UI.HtmlControls;
11
12
13
public partial class ClientServer_Default2:System.Web.UI.Page
15 {
String lspass = "";
17
protected void Page_Load (object sender, EventArgs e)
19 {
if (! IsPostBack)
21 {
this. BUTTON1.ATTRIBUTES.ADD ("onclick", "Javascript:return Checkall ();");
23}
24
25}
protected void Button1_Click (object sender, EventArgs e)
27 {
HttpCookie Mycookie_validcode = request.cookies["Fwcx_checkcode"];
if (Mycookie_validcode. Value.tostring ()! = Txt_validcode. Text)
30 {
Response.Write ("<script>");
Response.Write ("Alert (' captcha error ')");
Response.Write ("</script>");
return;
35}
36
37//First determine if the login name and email are present
The String sql = "SELECT * from t_users where u_username= '" + username. Text.trim () + "' and u_email= '" + email. Text.trim () + "' and u_class= ' 0 ' and u_valid= ' 1 '";
The most datatable dt = new DataTable ();
//dt = new SQLTool (). dataTable (SQL);
41
if (dt. Rows.Count < 1)
43 {
Response.Write ("<script>alert" (' Login name or email address is wrong! , please re-fill and try again. ');</script> ");
45
46}
+ Else
48 {
49//First give the current database t_users a temporary password
//response.write (Createrandomcode (8));
Wuyi Lspass = Createrandomcode (8);
T_users sql = "UPDATE: Set u_getpwd= '" + Lspass + "' where u_username= '" + username. Text.trim () + "' and u_email= '" + email. Text.trim () + "' and u_class= ' 0 ' and u_valid= ' 1 '";
//if (New SQLTool (). ExecuteSQL (SQL) >= 0)
54//{
SendEmail (email. Text.trim (), username. Text.trim ());
Response.Write ("<script>alert (' temporary password has been sent to your registered email, please change your password on the next page. '); window.location.href= ' getpwdconfirm.aspx ';</script> ");
57//}
58}
59}
public void SendEmail (string email, string name)
61 {
Try
63 {
JMail. Message jmessage = new JMail. Message ();
Jmessage. Charset = "GB2312";
Jmessage. from = "[email protected]";
67//Address
Jmessage. Mailserverusername = "86085005";
//SMTP Certification User name (note: For netease users, do not add to @163.com, as long as the front section can)
Jmessage. Mailserverpassword = "Kingseer";
//SMTP argument user name password
72
Jmessage. FromName = "108 Human Bank";
74//Sender
Jmessage. ReplyTo = "[email protected]";
76//Reply to address
Jmessage. c;//message content is HTML
Jmessage. Subject = "108 Human bank temporary password";
79
String strbody = "";
Bayi Strbody + = new functions (). Getinfoxx ("T_pagetexts", "P_name", "Retrieve password email feedback-Personal", "P_value"). Replace ("$", name). Replace ("@%", Lspass);
Jmessage. HTMLBody = strbody;
83//Mail Header
Jmessage. AddRecipient (email, "", "");
Jmessage. Send ("smtp.163.com", false);//e-mail smtp.163.com
Jmessage. Close ();//Closing the object, freeing the resource
87
88
89}
All-in-catch (Exception err)
91 {
Response.Write (ERR);
93}
94}
<summary>
96///function: Random string that produces mixed numbers and characters
</summary>
98//<param Name= "Codecount" > Number of Strings </param>
<returns></returns>
+ private string Createrandomcode (int codecount)
101 {
102
103//numeric and character mixed strings
104 String Allchar = "0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,l,m,n";
105//Split array
106 string[] Allchararray = Allchar. Split (', ');
107 String Randomcode = "";
108
109//Random number instances
System.Random rand = new System.Random (unchecked ((int) DateTime.Now.Ticks));
111 for (int i = 0; i < Codecount; i++)
112 {
113//Get a random number
int t = rand. Next (Allchararray. Length);
115//Synthetic random string
Randomcode + = allchararray[t];
117}
118 return Randomcode;
119}
120
121}

(ext.) ASP. NET implements forgotten password recovery code

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.