找回密码

<asp:LinkButton ID="butGetPSW" runat="server" Font-Underline="True"
                                            TabIndex="5" CausesValidation="False" OnClick="butGetPSW_Click">找回密码</asp:LinkButton>

后台:

 protected void butGetPSW_Click(object sender, EventArgs e)
    {
        if (txtLoginName.Text == null && txtLoginName.Text == "")
        {
            lblLogin.Text = "请输入登录名!";
            return;
        }
        string value = ZZ.Conn.Connection.getSqlValue("select count(1) from UserInfo where LoginName='" + txtLoginName.Text + "'");
        if (value.Equals("0"))
        {
            lblLogin.Text = "当前用户不存在!";
            return;
        }
        Session["LoginName"] = txtLoginName.Text;
        if (butGetPSW.Text == "找回密码")
        {
            Random r = new Random();
            Session["Number"] = r.Next(1000, 9999);
            string mall = ZZ.Conn.Connection.getSqlValue("select EmailAddress from UserInfo where LoginName='" + txtLoginName.Text + "'");
            if (mall != null && mall != "")
            {
                try
                {
                    MailMessage mailObj = new MailMessage();
                    mailObj.From = new MailAddress(Session["EmailAddress"].ToString()); //发送人邮箱地址
                    mailObj.To.Add(mall);   //收件人邮箱地址
                    mailObj.Subject = "验证信息";    //主题
                    mailObj.Body = "本次验证码:" + Session["number"];    //正文    
                    SmtpClient smtp = new SmtpClient();
                    smtp.Host = "smtp.qq.com";         //smtp服务器名称
                    smtp.UseDefaultCredentials = true;
                    smtp.Credentials = new NetworkCredential(Session["EmailAddress"].ToString(), Session["EmailPassWord"].ToString());  //发送人的登录名和密码
                    smtp.Send(mailObj);
                }
                catch (Exception ex)
                {
                    lblLogin.Text = "系统繁忙!请稍后再试";
                    return;
                }
            }
        }
        else
        {
            Session["Number"] = "0000";
        }
        Response.Redirect("~/SysTemMaintain/UserPower/FindPassWord.aspx");

    }

 

posted @ 2015-06-06 17:16  清空回声  阅读(240)  评论(0编辑  收藏  举报