66 lines
1.8 KiB
C#
66 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using DAL;
|
|
using Utils;
|
|
|
|
public partial class login : System.Web.UI.Page
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if(Session["username"] != null)
|
|
{
|
|
Response.Redirect("/index.aspx");
|
|
return;
|
|
}
|
|
}
|
|
|
|
protected void onLoginClick(object sender, EventArgs e)
|
|
{
|
|
if (Page.IsValid)
|
|
{
|
|
Entities entities = new Entities();
|
|
Usuario usuario = (from u in entities.Usuarios where u.nombre == username_box.Text select u).SingleOrDefault();
|
|
|
|
if (usuario == null)
|
|
{
|
|
error_message.Text = "El usuario o contraseña no son validos";
|
|
return;
|
|
}
|
|
|
|
if (!PasswordHash.Compare(password_box.Text, usuario.password))
|
|
{
|
|
error_message.Text = "El usuario o contraseña no son validos";
|
|
return;
|
|
}
|
|
|
|
Session["username"] = usuario.nombre;
|
|
Response.Redirect("/index.aspx");
|
|
}
|
|
}
|
|
|
|
protected void validateUsername(object sender, ServerValidateEventArgs e)
|
|
{
|
|
if (username_box.Text.Length > 15)
|
|
{
|
|
e.IsValid = false;
|
|
username_validator.Text = "El nombre de usuario es demasiado largo, maximo de 15 caracteres";
|
|
return;
|
|
}
|
|
e.IsValid = true;
|
|
}
|
|
|
|
protected void validatePassword(object sender, ServerValidateEventArgs e)
|
|
{
|
|
if (password_box.Text.Length > 15)
|
|
{
|
|
e.IsValid = false;
|
|
password_validator.Text = "La contraseña es demasiado larga, maximo de 15 caracteres";
|
|
return;
|
|
}
|
|
e.IsValid = true;
|
|
}
|
|
} |