protected void resetButton_Click(object sender, EventArgs e) { try { if (Page.IsValid) { String email = emailTextbox.Text; //Generate new password String range = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!&$#*@_-"; char[] charray = new char[8]; for (int i = 0; i < 8; i++) { charray[i] = range[generator.Next(range.Length)]; } String password = new string(charray); //Send new password to email address String subject = "Scrumbags - Password reset"; String body = "Dear,\n " + "You recently requested a password reset on our website.\n" + "This is your new password: "******"scriptkey", "<script>alert('Your new password has been sent to your email address');</script>"); Session.Abandon(); Response.AppendHeader("REFRESH", "1;URL=Login.aspx"); } } catch (HttpException ex) { ((Label)Page.Master.FindControl("errorMessageLabel")).Text = ex.Message; } catch (System.Net.Mail.SmtpException ex) { ((Label)Page.Master.FindControl("errorMessageLabel")).Text = ex.Message; } catch (IndexOutOfRangeException ex) { ((Label)Page.Master.FindControl("errorMessageLabel")).Text = ex.Message; } catch (Exception ex) { ((Label)Page.Master.FindControl("errorMessageLabel")).Text = ex.Message; } }
//Submit the registration form protected void submitButton_Click(object sender, EventArgs e) { string name = lastNameTextbox.Text + " " + firstNameTextbox.Text; string email = emailTextbox.Text.ToLower(); //normalize email if (Page.IsValid) { //Add user to DB try { DBQueries.Register(name, emailTextbox.Text, password1Textbox.Text); } catch (Exception ex) { Label errorMessageLabel = (Label)Page.Master.FindControl("errorMessageLabel"); errorMessageLabel.Text = "An error occured registering your account:"; errorMessageLabel.Text += "\n\n"; errorMessageLabel.Text = ex.Message; } //Send verification email String subject = "Scrumbags - Account creation"; String body = "Dear " + name + ",\n\n" + "You recently created an accounton our site.\n" + "Please use the following link to verify your account: " + "http://localhost:4333/UserVerification.aspx?email=" + email + "&hash=" + Hashing.GetHash(email); //juiste adres invullen!! try { MailSender mailsender = new MailSender(email, subject, body); mailsender.Send(); //Redirect to loginpage Page.ClientScript.RegisterStartupScript(this.GetType(), "scriptkey", "<script>alert('Your account has been created, an email has been sent to your email address to verify your account');</script>"); Response.AppendHeader("REFRESH", "1;URL=Login.aspx"); } catch (Exception ex) { Label errorMessageLabel = (Label)Page.Master.FindControl("errorMessageLabel"); errorMessageLabel.Text = "An error occured while seding your verification email"; errorMessageLabel.Text += "\n\n"; errorMessageLabel.Text = ex.Message; } } }