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 = "86085005@163.com";
67 // 发信地址
68 jmessage.MailServerUserName = "86085005";
69 //smtp认证用户名(注:如为网易用户,不加要@163.com,只要前面部分即可)
70 jmessage.MailServerPassWord = "kingseer";
71 // smtp论证用户名密码
72
73 jmessage.FromName = "108人力银行";
74 // 发信人
75 jmessage.ReplyTo = "86085005@163.com";
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 }

(转)asp.net实现忘记密码找回的代码的更多相关文章

  1. WordPress忘记密码找回登录密码的四种行之有效的方法

    WordPress忘记密码找回登录密码的四种行之有效的方法 PS:20170214更新,感谢SuperDoge同学提供的方法,登入phpMyAdmin后,先从左边选自己的数据库,然后点上面的 SQL ...

  2. Mysql数据库忘记密码找回方法

    Mysql数据库忘记密码找回 a 停止mysql服务 /etc/init.d/mysql stop b 使用--skip-grant-tables启动mysql,忽略授权登录验证 mysqld_saf ...

  3. 关于wordpress忘记密码 找回密码的方式

    1.通过直接修改数据库中密码的加密字符(如果wordpress的版本不同,那么此方法是不好实现的) 2.使用找回密码的方式:通过邮箱找回密码 前端登录密码错误后 会显示   错误); 方法二 打开WP ...

  4. linux 7忘记密码找回

    一.linux 7忘记密码二种更改方法 centos7/rhel7进入单用户方式和重置密码方式发生了较大变化,GRUB由b引导变成了ctrl+x引导.重置密码主要有rd.break和init两种方法. ...

  5. Oracle忘记密码找回

    生活中,容易忘记Oracle数据库system用户的密码,怎么办呢,小生带你一步步重新登上Oracle ,及时你密码忘记了. 1.打开cmd窗口,输入 sqlplus / as sysdba 2.运行 ...

  6. Mysql忘记密码找回步骤

    Mysql密码忘记找回步骤: 1.首先停止数据库 [root@localhost ~]# /etc/init.d/mysqld stop 2.使用--skip-grant-tables启动mysql, ...

  7. windows下MariaDB忘记密码找回

    1.首先停止数据库 2.找到my.ini文件 3.右键以记事本打开在Mysqld下添加如下一行保存,然后启动数据库 4.登录数据库会提示输入密码,默认回车即可 5.退出数据库,删除我们上面在my.in ...

  8. centos mysql忘记密码找回(仅限mysql5.7)

    1.停掉mysql 2.执行#mysqld_safe --user=mysql --skip-grant-tables --skip-networking & 3.#mysql 4.updat ...

  9. Mysql 5.7 安装 解压缩版 忘记密码

    [参考]Mysql 命令大全 [参考]MySQL 5.7.19 忘记密码 重置密码 配置文件my.ini示例 服务启动后停止 log配置 [参考]MySQL5.7.19 服务挂掉 自动关闭 mysql ...

随机推荐

  1. 你好,C++(29)脚踏两只船的函数不是好函数 5.4 函数设计的基本规则

    5.4  函数设计的基本规则 函数是C++程序的基本功能单元,就像一块块砖头可以有规则地垒成一座房子,而一个个函数也可以有规则地组织成一个程序.我们在大量使用他人设计好的函数的同时,也在设计大量的函数 ...

  2. CSS选择器解析

    通配符选择器 Universal Selector * { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizin ...

  3. php 产生不重复的随机数

    $arr=array();//创建数组 while(count($arr)<10){ $a = mt_rand(1000,9999);//产生随机数 if(!in_array($a,$arr)) ...

  4. 关于多本小说站的SEO—从”易读中文网”获得的心得体会

    从目前国内的网站流量来说,电影站,小说站,游戏站等的流量占总流量的比例还是很高的,许多站长把目光投入到了这几个方面,本文就着重来说对于小说站,尤其是多本小说站的SEO心得体会! 对于小说站来说,只要排 ...

  5. GET异步 请求图片步骤

    - (IBAction)getImage:(id)sender { //1,准备URL NSString *str = @"http://e.hiphotos.baidu.com/image ...

  6. Android Activity整体管理和关闭工具类封装

    如何彻底退出程序,在任意位置退出程序,如何管理当前的运行栈,知道activity的堆栈结构等,本文封装了一个Activity管理类,可以方便随时退出程序. /** * 应用程序Activity管理类: ...

  7. Android ListView特别属性用法

    由于这两天在做listView的东西,所以整理出来一些比较特别(不常用)的属性,通过设置这样的属性可以做出更加美观的列表 1.stackFromBottom属性,这只该属性之后你做好的列表就会显示你列 ...

  8. Android写入文件操作权限

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses- ...

  9. Web Server CA证书签名步骤和自签名测试,支持多域名

    Web Server支持HTTPS访问需要两个文件,私钥和证书.私钥和证书都放在服务器上,私钥用来加密数据,证书传递给客户端.自己签名的证书在传递给浏览器的时,因为证书不被信任,所以会弹出连接不安全, ...

  10. c++应用程序文件的编译过程

    这里讲下C++文件的编译过程及其中模板的编译过程: 一:一般的C++应用程序的编译过程.     一般说来,C++应用程序的编译过程分为三个阶段.模板也是一样的. 在cpp文件中展开include文件 ...