Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. public bool isLoggedIn()
  2. {
  3. return System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
  4. }
  5.  
  6. public void Login_OnClick(object sender, EventArgs args)
  7. {
  8. string email = UserName.Text;
  9. string password = Password.Text;
  10. string errorMsg = string.Empty;
  11. bool cb = cb_agreeterms.Checked;
  12.  
  13. if (tests)
  14. {
  15. // The code in here tests to see if email, password, etc. have been filled out.
  16. // This works 100% of the time and is NOT a problem.
  17. }
  18. else
  19. {
  20. // Validate user.
  21. if (Membership.ValidateUser(email, password))
  22. {
  23. // Get the logged in user
  24. MembershipUser user = Membership.GetUser(email);
  25.  
  26. if (user.IsLockedOut)
  27. {
  28. user.UnlockUser();
  29. }
  30.  
  31. // Gets a datatable of the user details in our general database
  32. DataTable dtUserData = this.dbData.GetUserByEmail(user.UserName);
  33.  
  34. if (dtUserData.Rows.Count > 0)
  35. {
  36. FormsAuthentication.SetAuthCookie(user.UserName, true);
  37.  
  38. // The details for the userId, screenName, etc. below get set by looking at the row 0 in datatable
  39.  
  40. // The LoginSession function intializes a session with a guid and saves all the data into an Application Context. This creates a SessionGuid cookie which I see get created on FF and Chrome (and always on IE).
  41. LoginSession(userId, screenName, permissionLevel, user.UserName);
  42.  
  43. Response.Redirect("../myinternalsite.aspx");
  44. }
  45. }
  46. else if (UserExistsInMembership(email))
  47. {
  48. // Tested this out and entering bad credentials fails the login and error is shown correctly on screen in the login control.
  49.  
  50. // We have failed to login.
  51. ShowLoginError("E-mail or password is incorrect.");
  52. }
  53. }
  54. }
  55.  
  56. public bool isLoggedIn()
  57.  
  58. // authenticationConnection works and links correctly to the auth database just fine.
  59. <sessionState timeout="120"/>
  60.  
  61. <membership defaultProvider="SqlProvider">
  62.  
  63. <providers>
  64.  
  65. <add connectionStringName="authenticationConnection" applicationName="Auth" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" name="SqlProvider" type="System.Web.Security.SqlMembershipProvider" requiresQuestionAndAnswer="false" passwordFormat="Hashed" enablePasswordReset="true" maxInvalidPasswordAttempts="1000" passwordAttemptWindow="1" />
  66.  
  67. </providers>
  68.  
  69. </membership>
  70.  
  71. <roleManager enabled="true" defaultProvider="SqlRoleManager">
  72.  
  73. <providers>
  74.  
  75. <add name="SqlRoleManager" type="System.Web.Security.SqlRoleProvider" connectionStringName="authenticationConnection" applicationName="MyApp"/>
  76.  
  77. </providers>
  78.  
  79. </roleManager>
  80.  
  81. <identity impersonate="true"/>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement