Example #1
0
    protected void OnSendingMail(object sender, MailMessageEventArgs e)
    {
        //Event handler for event that occurs before the user is sent a password in e-mail
        MembershipUser user     = Membership.GetUser(this.ctlRecoverPW.UserName);
        string         password = Membership.GeneratePassword(6, 0);

        user.ChangePassword(user.GetPassword(), password);

        //Set flag that forces user to change password on next login
        ProfileCommon profile = new ProfileCommon().GetProfile(user.UserName);

        profile.PasswordReset = true;
        profile.Save();

        //Send an email
        EmailServices esvcs = new EmailServices();

        esvcs.SendPasswordResetMessage(user.UserName, user.Email, password);
        e.Cancel = true;
    }