Está en la página 1de 4

using System.Data.SqlClient; using System.Configuration; public partial class Login : System.Web.UI.

Page { protected void BtnLogin_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistroConnectionString"].Con nectionString); con.Open(); String CmdStr = "Select Count(*) From Table1 Where NombreUsuario='" + TxtUsuario.Text + "'"; SqlCommand CheckUser = new SqlCommand(CmdStr, con); int Temp=Convert.ToInt32(CheckUser.ExecuteScalar().ToString()); if (Temp == 1) { String CmdStr2 = "Select Contrasea From Table1 Where NombreUsuario='" + TxtUsuario.Text + "'"; SqlCommand pass = new SqlCommand(CmdStr2, con); String Contrasea = pass.ExecuteScalar().ToString(); con.Close(); if (Contrasea == txtPassword.Text)

{ Session["New"] = "Bienvenido"+TxtUsuario.Text; Response.Redirect("Secure.aspx"); } else { LblMensaje.Visible = true; LblMensaje.Text = "Contrasea invalida"; } } else { LblMensaje.Visible = true; LblMensaje.Text = "Usuario incorrecto"; } } }

using System.Data.SqlClient; using System.Configuration; public partial class Registro : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistroConnectionString"].Con nectionString); con.Open(); String CmdString = "select count(*) From Table1 where NombreUsuario='" + TxtUsuario + "'"; SqlCommand UserExist = new SqlCommand(CmdString, con); int temp = Convert.ToInt32(UserExist.ExecuteScalar().ToString()); con.Close(); if (temp == 1) { Response.Write("Usuario valido , rpobar otro registro"); } }

} protected void Enviar_Click(object sender, EventArgs e) { } protected void Enviar_Click1(object sender, EventArgs e) { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistroConnectionString"].Con nectionString); con.Open(); string InsCmd = "Insert into Table1(NombreUsuario, Contrasea, Email, Direccion, Pais) Values(@NombreUsuario, @Contrasea, @Email, @Direccion, @Pais)"; SqlCommand InserUser = new SqlCommand(InsCmd, con); InserUser.Parameters.AddWithValue("@NombreUsuario", TxtUsuario.Text); InserUser.Parameters.AddWithValue("@Contrasea", TxtContrasea.Text); InserUser.Parameters.AddWithValue("@Email", TxtEmail.Text); InserUser.Parameters.AddWithValue("@Direccion", TxtDireccion.Text); InserUser.Parameters.AddWithValue("@Pais", DropPais.SelectedItem.ToString()); try { InserUser.ExecuteNonQuery(); con.Close(); Response.Redirect("Login.aspx"); } catch (Exception er) { Response.Write("Mensaje error" + er.Message); } finally { //Eso es todo } } }

public partial class Secure : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Session["New"] != null) { Label1.Text = Session["New"].ToString(); } else { Response.Redirect("Login.aspx"); } }

protected void BtnCerrar_Click(object sender, EventArgs e) { Session["New"] = null; Response.Redirect("Login.aspx"); } }