Guest User

Untitled

a guest
Jan 17th, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. <system.web>
  2. <authentication mode="Forms">
  3. <forms loginUrl="~/Login.aspx" timeout="5000" />
  4. </authentication>
  5. </system.web>
  6.  
  7. <system.web>
  8.  
  9. <authorization>
  10. <allow users="admin"/>
  11. <allow users="manager"/>
  12. <deny users="*"/>
  13. </authorization>
  14. </system.web>
  15.  
  16. <div style="margin: 0 60px 0;">
  17. <label>
  18. UserName:</label>
  19. <asp:TextBox ID="txtUserName" CssClass="text big" TabIndex="1"
  20. runat="server"></asp:TextBox>
  21. <asp:RequiredFieldValidator ID="RFUsername" Display="None" runat="server" ControlToValidate="txtUserName"
  22. ErrorMessage="Must enter a username"></asp:RequiredFieldValidator>
  23. <br />
  24. <label>
  25. Password:</label><br />
  26. <asp:TextBox ID="txtPassword" CssClass="text big" TabIndex="2"
  27. runat="server" TextMode="Password"></asp:TextBox>
  28. <br />
  29. <asp:RequiredFieldValidator ID="RFPassword" runat="server" Display="None" ControlToValidate="txtPassword"
  30. ErrorMessage="Password is mandatory"></asp:RequiredFieldValidator>
  31.  
  32.  
  33.  
  34. <asp:Button ID="btnLogin" runat="server" CssClass="submit" OnClick="btnLogin_Click"
  35. TabIndex="4" />
  36.  
  37.  
  38. </div>
  39.  
  40. protected void btnLogin_Click(object sender, EventArgs e)
  41. {
  42. lblLoginFail.Text = "";
  43.  
  44. if (txtUserName.Text == "")
  45. {
  46. lblLoginFail.Text += "UserName is missing" + Environment.NewLine;
  47. lblLoginFail.Visible = true;
  48. }
  49. if (txtPassword.Text == "")
  50. {
  51. lblLoginFail.Text += "Password is missing" + "rn";
  52. lblLoginFail.Visible = true;
  53. }
  54. string role = system.CheckAdminLogin(txtUserName.Text, txtPassword.Text);
  55. if (role == Role.admin.ToString() || role == Role.manager.ToString())
  56. {
  57. Users _user = _users.GetUserByUserName(txtUserName.Text);
  58.  
  59. FormsAuthentication.SetAuthCookie(role, false);
  60. Session.Add("UserName", txtUserName.Text);
  61. Session.Add("UserID", _user.ID);
  62. Response.Redirect("System/ShowActivities.aspx");
  63.  
  64. }
  65. else
  66. {
  67. if (txtPassword.Text != "" && txtUserName.Text != "")
  68. {
  69. lblLoginFail.Text = Application["Wrong_login_data"].ToString();
  70. lblLoginFail.Visible = true;
  71. }
  72. }
  73. }
Add Comment
Please, Sign In to add comment