Advertisement
rukusha

Untitled

Mar 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Data.SqlClient;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. using Microsoft.Owin.Security.Cookies;
  11. using Microsoft.AspNet.Identity;
  12. using Microsoft.AspNet.Identity.EntityFramework;
  13.  
  14.  
  15.  
  16. using System.Data;
  17. using Microsoft.Owin.Security;
  18.  
  19. namespace Shop2017
  20. {
  21. public partial class Login : System.Web.UI.Page
  22. {
  23. SqlConnection connection = new SqlConnection(@"Data Source = SQL2016.fse.network; Initial Catalog = db_1620708_webuser; Persist Security Info=True;User ID = user_db_1620708_webuser; Password=Chester1991");
  24.  
  25. DataSet Data = new DataSet();
  26.  
  27. protected void Page_Load(object sender, EventArgs e)
  28. {
  29.  
  30. }
  31.  
  32. protected void btnSignUp_Click(object sender, EventArgs e)
  33. {
  34. Response.Redirect("register.aspx");
  35. }
  36.  
  37. protected void btnLogin_Click(object sender, EventArgs e)
  38. {
  39. var identityDbContext = new IdentityDbContext(@"Data Source = SQL2016.fse.network; Initial Catalog = db_1620708_webuser; Persist Security Info = True; User ID = user_db_1620708_webuser; Password = Chester1991");
  40. var userStore = new UserStore<IdentityUser>(identityDbContext);
  41. var userManager = new UserManager<IdentityUser>(userStore);
  42. var user = userManager.Find(TextUsername.Text, txtPassword.Text);
  43.  
  44. //Cookie attempt
  45. HttpCookie UserLogin = new HttpCookie("UserCookieInfo");
  46. UserLogin["Username"] = TextUsername.Text;
  47. UserLogin["Password"] = txtPassword.Text;
  48. UserLogin.Expires = DateTime.Now.AddDays(60);
  49. Response.Cookies.Add(UserLogin);
  50.  
  51. Session["Username"] = TextUsername.Text;
  52. Session["Password"] = txtPassword.Text;
  53.  
  54. if (user != null)
  55. {
  56. // Finds username
  57. lBLInvalid.Text = "Welcome to Bytes " + Session["Username"];
  58. }
  59. else
  60. {
  61. //Invalid credentials
  62. lBLInvalid.Text = "Invalid username or password.";
  63. }
  64.  
  65. }
  66. private void LogUserIn(UserManager<IdentityUser> usermanager, IdentityUser user)
  67. {
  68. var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
  69. var userIdentity = usermanager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
  70. authenticationManager.SignIn(new AuthenticationProperties() { }, userIdentity);
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement