【问题标题】:How to update the AutoGeneratedPassword into Database?如何将自动生成的密码更新到数据库中?
【发布时间】:2015-10-06 03:19:50
【问题描述】:

使用系统;

使用 System.Collections.Generic;

使用 System.Linq;

使用 System.Web;

使用 System.Web.UI;

使用 System.Web.UI.WebControls;

使用 System.Data;

使用 System.Data.SqlClient;

使用 System.Net.Mail;

使用 System.Net;

使用 System.Configuration;

public partial class forgotpw : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)
{

}

private string getRandomPassword()
{

    string allowedChars = "";

    allowedChars = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,";

    allowedChars += "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,";

    allowedChars += "1,2,3,4,5,6,7,8,9,0,!,@,#,$,%,&,?";

    char[] sep = { ',' };

    string[] arr = allowedChars.Split(sep);

    string PasswordString = "";

    string temp = "";

    Random rand = new Random();

    for (int i = 0; i < 8; i++)
    {

        temp = arr[rand.Next(0, arr.Length)];

        PasswordString += temp;

    }

    return PasswordString;

}


protected void btnGenerate_Click(object sender, EventArgs e)
{

    SmtpClient client = new SmtpClient("smtp.gmail.com");

    var message = new MailMessage();

    client.Host = "smtp.gmail.com";

    client.Port = 587;

    client.UseDefaultCredentials = false;

    client.Credentials = new System.Net.NetworkCredential("my@gmail.com", "mypw");

    client.EnableSsl = true;

    MailAddress SendFrom = new MailAddress("my@gmail.com", "mygmail");

    try
    {

        String Password = getRandomPassword();

        MailAddress SendTo = new MailAddress(txtEmail.Text);

        message = new MailMessage(SendFrom, SendTo);

        message.Subject = "Auto Generated Password";

        message.Body = "Auto Generated Password has been generated, login using below creditiantials:<br/>" + "<br/>LoginID :" + txtEmail.Text + "<br/>Password :" + Password;

        message.IsBodyHtml = true;

        message.Priority = MailPriority.High;

        client.ServicePoint.MaxIdleTime = 0;

        client.ServicePoint.ConnectionLimit = 1;

        client.Send(message);

        ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Mail Sent successfully');</script>");

    }

    catch
    {

        ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('Unexpected Error Occur TryAgain ');</script>");

    }

}

自动生成的密码已发送到电子邮件,但未在数据库中更新...请帮助..谢谢

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    您必须以任何方式将新生成的密码保存到您的数据库中,您没有访问您的数据库。在发送电子邮件之前,请检查您用于保存数据和更新用户信息的方法。我建议向用户发送一个链接以重置密码并且不要暴露新密码,因为它更安全。

    纳尔逊帕拉。

    【讨论】:

      猜你喜欢
      • 2013-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-24
      • 2011-09-06
      • 1970-01-01
      相关资源
      最近更新 更多