• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

asp.net[忘记密码]【邮箱取回密码】

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
3 <html xmlns="http://www.w3.org/1999/xhtml" >
4 <head id="Head1" runat="server">
5 <title>个人会员密码找回</title>
6 <link href="/style.css" rel="stylesheet" type="text/css" />
7 <script language="javascript" type="text/javascript">
8 // 检查 E-mail 是否已被注册
9 function CheckEmail()
10 {
11 var e = document.getElementById("email").value;
12 if(e != "")
13 {
14 if(!/(\S)+[@]{1}(\S)+[.]{1}(\w)+/.test(e))
15 {
16 alert("请输入格式正确的E-mail 地址!");
17 var email = document.getElementById ( "email" );
18 email.value = "";
19 email.focus ();
20 }
21 }
22 }
23
24 function checkAll()
25 {
26 var ee = document.getElementById("username").value;
27 if(ee == "")
28 {
29 alert('登录名称不能为空');
30 return false;
31 }
32
33 var e = document.getElementById("email").value;
34 if(e == "")
35 {
36 alert('Emial不能为空');
37 return false;
38 }
39
40
41 }
42
43 </script>
44 </head>
45 <body>
46 <form id="form1" runat="server">
47 <div>
48 <table width="778" border="0" align="center" cellpadding="5" cellspacing="0" class="table_huang">
49 <tr>
50 <td colspan="2" class="TD_huang_14_write"> <span style="font-size: 11pt">>> 获取密码</span></td>
51 </tr>
52 <tr>
53 <td width="26"></td>
54 <td width="724"><table width="90%" border="0" cellspacing="2" cellpadding="5">
55 <tr>
56 <td width="23%"><div align="right">用户名:</div></td>
57 <td width="77%">
58 <asp:TextBox ID="username" runat="server" Width="150px" ></asp:TextBox></td>
59 </tr>
60 <tr>
61 <td><div align="right">注册时填写的Email:</div></td>
62 <td>
63 <asp:TextBox ID="email" runat="server" Width="200px" ></asp:TextBox></td>
64 </tr>
65 <tr>
66 <td><div align="right">验证码:</div></td>
67 <td><table width="100%">
68 <tr>
69 <td align="left" valign="top" style="width: 64px"><asp:TextBox ID="txt_validcode" runat="server" Height="15px" Width="62px"></asp:TextBox> </td>
70 <td align="left" valign="top"><img id="yzm" src="../ValidateCode.aspx" /></td>
71 </tr>
72 </table></td>
73 </tr>
74 <tr>
75
76 <td colspan="2" style="text-align: center">
77 <asp:Button ID="Button1" runat="server" Text=" 找回密码 " /></td>
78 </tr>
79 </table> </td>
80 </tr>
81 </table>
82 </div>
83 </form>
84 </body>
85 </html>

后端源码:

  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;
10 using System.Web.UI.HtmlControls;
11
12
13
14 public partial class ClientServer_Default2 : System.Web.UI.Page
15 {
16 string lspass = "";
17
18 protected void Page_Load(object sender, EventArgs e)
19 {
20 if (!IsPostBack)
21 {
22 this.Button1.Attributes.Add("onclick", "javascript:return checkAll();");
23 }
24
25 }
26 protected void Button1_Click(object sender, EventArgs e)
27 {
28 HttpCookie myCookie_validcode = Request.Cookies["FWCX_CheckCode"];
29 if (myCookie_validcode.Value.ToString() != txt_validcode.Text)
30 {
31 Response.Write("<script>");
32 Response.Write("alert('验证码错误')");
33 Response.Write("</script>");
34 return;
35 }
36
37 //首先判断该登录名称和email是否存在
38 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'";
39 DataTable dt = new DataTable();
40 //dt = new SQLTool().dataTable(sql);
41
42 if (dt.Rows.Count < 1)
43 {
44 Response.Write("<script>alert('登录名称或Email地址错误!,请重新填写后再试。');</script>");
45
46 }
47 else
48 {
49 //首先给现在的数据库t_users附上一个临时密码
50 //Response.Write(CreateRandomCode(8));
51 lspass = CreateRandomCode(8);
52 sql = "update t_users set u_getpwd='" + lspass + "' where u_username='" + username.Text.Trim() + "' and u_email='" + email.Text.Trim() + "' and u_class='0' and u_valid='1'";
53 //if (new SQLTool().ExecuteSql(sql) >= 0)
54 //{
55 sendEmail(email.Text.Trim(), username.Text.Trim());
56 Response.Write("<script>alert('临时密码已经发送到您的注册Email中,请在下一页面中修改密码。');window.location.href='getpwdconfirm.aspx';</script>");
57 //}
58 }
59 }
60 public void sendEmail(string email, string name)
61 {
62 try
63 {
64 jmail.Message jmessage = new jmail.Message();
65 jmessage.Charset = "GB2312";
66 jmessage.From = "[email protected]";
67 // 发信地址
68 jmessage.MailServerUserName = "86085005";
69 //smtp认证用户名(注:如为网易用户,不加要@163.com,只要前面部分即可)
70 jmessage.MailServerPassWord = "kingseer";
71 // smtp论证用户名密码
72
73 jmessage.FromName = "108人力银行";
74 // 发信人
75 jmessage.ReplyTo = "[email protected]";
76 // 回复地址
77 jmessage.C;//邮件内容为html
78 jmessage.Subject = "108人力银行临时密码";
79
80 string strbody = "";
81 strbody += new functions().getInfoXX("t_pagetexts", "p_name", "找回密码邮件反馈-个人", "p_value").Replace("$", name).Replace("@%", lspass);
82 jmessage.HTMLBody = strbody;
83 // 邮件标题
84 jmessage.AddRecipient(email, "", "");
85 jmessage.Send("smtp.163.com", false);//发送邮件smtp.163.com
86 jmessage.Close();//关闭对象,释放资源
87
88
89 }
90 catch (Exception err)
91 {
92 Response.Write(err);
93 }
94 }
95 /// <summary>
96 /// 功能:产生数字和字符混合的随机字符串
97 /// </summary>
98 /// <param name="codecount">字符串的个数</param>
99 /// <returns></returns>
100 private string CreateRandomCode(int codecount)
101 {
102
103 // 数字和字符混合字符串
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 //分割成数组
106 string[] allchararray = allchar.Split(',');
107 string randomcode = "";
108
109 //随机数实例
110 System.Random rand = new System.Random(unchecked((int)DateTime.Now.Ticks));
111 for (int i = 0; i < codecount; i++)
112 {
113 //获取一个随机数
114 int t = rand.Next(allchararray.Length);
115 //合成随机字符串
116 randomcode += allchararray[t];
117 }
118 return randomcode;
119 }
120
121 }



前端页面:

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
电子书下载:ProASP.NET4inC#2010发布时间:2022-07-10
下一篇:
ASP.NET-视图状态概述发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap