protected void btnAceptar_Click(object sender, EventArgs e) { PassRecover passRecover; passRecover = (PassRecover)Session["PassRecover"]; if (txtCodigo.Text.ToUpper() == passRecover.Code) { Session["Email"] = passRecover.Email; Response.Redirect("NuevaContraseña.aspx"); } else { val++; int result = 3 - val; if (result > 0) { lblErrorMessage.Text = "Código incorrecto: Intentos restantes: " + result; } else { val = 0; Session["InternalPassSession"] = new PassRecover { NumberOfTries = 3, LastTry = DateTime.Now }; Response.Redirect("RecuperarContraseña.aspx"); } } }
protected void btnAceptar_Click(object sender, EventArgs e) { DateTime birthdate; if (DateTime.TryParse(txtFecha.Text, out birthdate)) { PassRecover PassRecover = passRecoverSession(birthdate); if (PassRecover.IsEmailAndBirthdayCorrect() && ValidateCaptcha()) { if (HasPasswordRecoveryPermission(PassRecover)) { string code = RandomString(5); PassRecover.Code = code; string message = string.Format("Usted ha solicitado una recuperación de contraseña en el sistema de ProcessSA, su código de recuperación es:" + "</br>" + "<h1>{0}</h1>" + "</br>" + "En caso que usted no haya solicitado este cambio, ignore este mensaje", code); SMTPHelper SMTPHelper = new SMTPHelper("*****@*****.**", PassRecover.Email, message, "Recuperación de contraseña", null); if (SMTPHelper.enviaMail()) { Session["PassRecover"] = PassRecover; Response.Redirect("CodigoContraseña.aspx"); } else { lblErrorMessage.Text = "Error del servidor al enviar el mensaje, contacte al administrador"; } } else { lblErrorMessage.Text = "Su cuenta no posee el permiso de recuperar contraseña"; } } else { lblErrorMessage.Text = "El email, la fecha de nacimiento o el captcha son inválidos, número de intentos restantes: " + (3 - PassRecover.NumberOfTries); CheckNumberOfTries(PassRecover.NumberOfTries); } } else { lblErrorMessage.Text = "Error en lectura de fecha"; } }
public void CanTryAgain() { if (Session["InternalPassSession"] != null) { PassRecover passRecover = (PassRecover)Session["InternalPassSession"]; TimeSpan span = DateTime.Now.Subtract(passRecover.LastTry); if (passRecover.NumberOfTries > 2) { if (span.TotalMinutes > 4) { Session["InternalPassSession"] = null; } else { Session["ExcessError"] = "Intente nuevamente en " + (5 - ((int)(span.TotalMinutes))).ToString() + " minutos"; Response.Redirect("Login.aspx"); } } } }
private PassRecover passRecoverSession(DateTime birthdate) { PassRecover passRecover; if (Session["InternalPassSession"] == null) { passRecover = new PassRecover() { Email = txtEmail.Text, Birthdate = birthdate }; } else { passRecover = (PassRecover)Session["InternalPassSession"]; } passRecover.NumberOfTries++; passRecover.LastTry = DateTime.Now; Session["InternalPassSession"] = passRecover; return(passRecover); }
private bool HasPasswordRecoveryPermission(PassRecover passRecover) { int idPasswordRecoverPermission = 34; return(passRecover.HasPermission(idPasswordRecoverPermission)); }