Guest User

Untitled

a guest
Dec 10th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. using System;
  2. using System.Configuration;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.HtmlControls;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.WebControls.WebParts;
  11. using System.Xml.Linq;
  12. using LN;
  13.  
  14. public partial class _Default : System.Web.UI.Page
  15. {
  16. static String password;
  17. static String usuario;
  18. static int idUser;
  19. static worldJobs wJ;
  20. static DataSet ds;
  21. static DataTable tabla;
  22.  
  23. protected void Page_Load(object sender, EventArgs e)
  24. {
  25. if (!Page.IsPostBack)
  26. {
  27. LoginMenu.UserName = "";
  28. wJ = new worldJobs();
  29. ds = wJ.getBaseDatosDesc().getDataSet();
  30. tabla = new DataTable();
  31. }
  32. }
  33. protected void LoginMenu_Authenticate(object sender, AuthenticateEventArgs e)
  34. {
  35. usuario = LoginMenu.UserName.ToString();
  36. password = LoginMenu.Password.ToString();
  37.  
  38. if (!usuario.Equals("") && !password.Equals(""))
  39. {
  40. #region Comprobamos
  41.  
  42. String user = "";
  43. String pass = "";
  44. String tipo = "";
  45. Boolean existe = false;
  46.  
  47. tabla = ds.Tables["Usuario"];
  48. for (int i = 0; i < tabla.Rows.Count; i++)
  49. {
  50. idUser = int.Parse(tabla.Rows[i][0].ToString());
  51. user = tabla.Rows[i][1].ToString();
  52. pass = tabla.Rows[i][2].ToString();
  53.  
  54. if (user.Equals(usuario) && pass.Equals(password))
  55. {
  56. tipo = tabla.Rows[i][3].ToString();
  57. existe = true;
  58. break;
  59. }
  60. }
  61.  
  62. #endregion
  63.  
  64. if (existe == true)
  65. {
  66. #region Si existe y es de tipo Persona
  67.  
  68. if (tipo.Equals("Persona"))
  69. {
  70. // El usuario que se conecta es de tipo Persona Normal
  71. Response.Cookies["NombreUsuario"].Value = usuario;
  72. Session["NombreUsuario"] = usuario;
  73. Session["Usuario"] = idUser;
  74. LoginMenu.UserName = "";
  75. Response.Redirect("usuario.aspx");
  76. }
  77. #endregion
  78.  
  79. #region Si existe y es de tipo Empresa
  80.  
  81. else if (tipo.Equals("Empresa"))
  82. {
  83. // El usuario que se conecta es de tipo Persona Normal
  84. Response.Cookies["NombreUsuario"].Value = usuario;
  85. Session["NombreUsuario"] = usuario;
  86. Session["Usuario"] = idUser;
  87. LoginMenu.UserName = "";
  88. Response.Redirect("empresa.aspx");
  89. }
  90.  
  91. #endregion
  92. }
  93. }
  94. }
  95. }
Add Comment
Please, Sign In to add comment