Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data;
- using System.Text;
- using System.Configuration;
- using System.Net.Mail;
- using System.Net;
- using MySql.Data.MySqlClient;
- //using SimpleCrypto;
- namespace SoftwareChampions_Col.Vista
- {
- public partial class recuperarcontraseña : System.Web.UI.Page
- {
- MySqlConnection con = new MySqlConnection(@"Data Source=localhost; Database=championscol; User ID=root; Password=123456789");
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- Label1.Text = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
- }
- Button2.Visible = false;
- Button3.Visible = false;
- Label1.Visible = false;
- Label2.Visible = false;
- TextBox2.Visible = false;
- }
- protected void ValidacionEmail()
- {
- string Correo = TextBox1.Text.Trim();
- if (Correo == "")
- {
- Label2.Visible = true;
- Label2.Text = "* Por favor debe de llenar el campo";
- }
- else
- {
- con.Open();
- MySqlCommand cmd = con.CreateCommand();
- cmd.CommandType = CommandType.Text;
- cmd.CommandText = "select * from accounts where Email='" + TextBox1.Text + "'";
- cmd.ExecuteNonQuery();
- DataTable dt = new DataTable();
- MySqlDataAdapter da = new MySqlDataAdapter(cmd);
- da.Fill(dt);
- foreach (DataRow dr in dt.Rows)
- {
- if (dt.Rows.Count > 0)
- {
- Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Hemos enviado un codigo de recuperacion a su correo');</script>");
- //cmd.CommandText = "insert into accounts(CodigoVerficacion) values (?CodigoVerficacion)";
- EnviarCorreo(Correo);
- Response.Redirect("codigoverificacion.aspx");
- }
- }
- con.Close();
- Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Correo incorrecto');</script>");
- }
- }
- public string GeneradorDeCodigos(int longitud)
- {
- string caracteres = "12J45K789T";
- StringBuilder res = new StringBuilder();
- Random rnd = new Random();
- while (0 < longitud--)
- {
- res.Append(caracteres[rnd.Next(caracteres.Length)]);
- }
- return res.ToString();
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- ValidacionEmail();
- }
- public void EnviarCorreo(string Destino)
- {
- string correo = TextBox1.Text;
- string password = GeneradorDeCodigos(10);
- string correoAdmin = ConfigurationManager.AppSettings["CorreoElectronico"].ToString();
- string ContraAdmin = ConfigurationManager.AppSettings["ContraseñaCorreo"].ToString();
- string Asunto = "Recuperar contraseña Champions_Col[Servidor Privado]";
- string Body = "su codigo de verificacion es " + password + " recuerde cambiar la contraseña por una facil de recordar.";
- var smtp = new SmtpClient();
- {
- smtp.Host = "smtp-mail.outlook.com";
- smtp.Port = 587;
- smtp.EnableSsl = true;
- smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
- smtp.Credentials = new NetworkCredential(correoAdmin, ContraAdmin);
- smtp.Timeout = 10000;
- }
- try
- {
- smtp.Send(correoAdmin, Destino, Asunto, Body);
- VaciarCampo();
- }
- catch (Exception)
- {
- Response.Write("No se puedo enviar el email");
- }
- }
- void VaciarCampo()
- {
- TextBox1.Text = "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement