protected void Button1_Click(object sender, EventArgs e) { var email = TextBox1.Text; var pass = TextBox3.Text; var nombre = TextBox2.Text; var apellidos = TextBox5.Text; var passconf = TextBox4.Text; var roll = DropDownList1.SelectedValue; var codpass = 0; EnvioCorreo.Correo correo = new EnvioCorreo.Correo(); var rand = new Random(); var numconf = (int)(rand.Next(1000000, 10000000)); try { bd = new AccesoADatos.Datos(); int resul; int a = bd.AbrirSesion(); if (a == 0) { resul = bd.registrar(nombre, apellidos, numconf, false, email, pass, codpass); } bd.cerrarConexion(); var sol = correo.enviarEmail(email, numconf, "https://localhost:44394/Confirmar.aspx"); } catch (Exception ex) { ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Hay algun dato mal insertado.');", true); } }
//0-> no existe correo //1-> Todo correcto. //2-> Ha habido algun error public int CambiarContrasenaCorreo(String correo, String pagin) { int esta = comprobarCorreo(correo); if (esta == 1) { try { //Creacion del numero aleatorio var rand = new Random(); int num = rand.Next(100000, 999999); command = new SqlCommand("UPDATE Usuarios SET codpass = @value WHERE email=@email;", cnn); command.Parameters.Add("@email", System.Data.SqlDbType.VarChar); command.Parameters["@email"].Value = correo; command.Parameters.Add("@value", System.Data.SqlDbType.VarChar); command.Parameters["@value"].Value = num; command.ExecuteNonQuery(); //Ahora mandaremos el correo. EnvioCorreo.Correo cor = new EnvioCorreo.Correo(); if (cor.cambiarContraseña(correo, num, pagin) == 2) { return(2); } return(1); } catch { return(2); } } else { return(0); } }