user2235949
user2235949

Reputation: 31

How to make a "Reset Password"?

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.

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); 

       }
   }
}

Upvotes: 1

Views: 313

Answers (1)

Eugene Pavlov
Eugene Pavlov

Reputation: 698

Put data you need like this:

msg.From = new MailAddress("[email protected]");
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):

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.

Upvotes: 1

Related Questions