如何制作“重置密码”?

时间:2022-11-15 13:09:35

How can I make this code send a new generated password or the user its old password?

如何让此代码发送新生成的密码或用户的旧密码?

I figured out how to let the code send a email! The sender is not the problem but the receiver is. Where EmailAdresNaar must be replaced with an email that someone puts into a text box or something.

我想出了如何让代码发送电子邮件!发送者不是问题,但接收者是。其中EmailAdresNaar必须替换为某人放入文本框或其他内容的电子邮件。

public void SendEmail()
    {



        string emailAdresVan = "invoerenSVP";
        string password = "invoerenSVP";


        MailMessage msg = new MailMessage();

        msg.From = new MailAddress(emailAdresVan);
        msg.To.Add(new MailAddress(EmailAdresNaar));
        msg.Subject = Onderwerp;
        msg.Body = Bericht;
        msg.IsBodyHtml = true;


        SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587);

        NetworkCredential loginInfo = new NetworkCredential(emailAdresVan, password);


        smtpClient.EnableSsl = true;
        smtpClient.UseDefaultCredentials = true;
        smtpClient.Credentials = loginInfo;

        smtpClient.Send(msg); 

       }
   }
}

1 个解决方案

#1


1  

Put data you need like this:

把你需要的数据放在这样:

msg.From = new MailAddress("support@yoursite.com");
msg.To.Add(new MailAddress(UserEmailTextBox.Text));
msg.Subject = "New Password";
msg.Body = GenerateNewPassword();

and example of method GenerateNewPassword(), but you should make it much more complex to return randomly generated new password (you need to google for different variations of implementation):

和方法GenerateNewPassword()的例子,但你应该让返回随机生成的新密码更复杂(你需要google以获得不同的实现变体):

public string GenerateNewPassword()
{
    string new_pass = "";
    // generate new password
    return new_pass;
}

Ideally, you should make another page like PasswordsReset.aspx, and send to user link to this page with some kind of GUID, where user can create new password by himself.

理想情况下,您应该创建另一个页面,如PasswordsReset.aspx,并使用某种GUID发送到此页面的用户链接,用户可以自己创建新密码。

#1


1  

Put data you need like this:

把你需要的数据放在这样:

msg.From = new MailAddress("support@yoursite.com");
msg.To.Add(new MailAddress(UserEmailTextBox.Text));
msg.Subject = "New Password";
msg.Body = GenerateNewPassword();

and example of method GenerateNewPassword(), but you should make it much more complex to return randomly generated new password (you need to google for different variations of implementation):

和方法GenerateNewPassword()的例子,但你应该让返回随机生成的新密码更复杂(你需要google以获得不同的实现变体):

public string GenerateNewPassword()
{
    string new_pass = "";
    // generate new password
    return new_pass;
}

Ideally, you should make another page like PasswordsReset.aspx, and send to user link to this page with some kind of GUID, where user can create new password by himself.

理想情况下,您应该创建另一个页面,如PasswordsReset.aspx,并使用某种GUID发送到此页面的用户链接,用户可以自己创建新密码。