Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Data.SqlClient;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using Microsoft.Owin.Security.Cookies;
- using Microsoft.AspNet.Identity;
- using Microsoft.AspNet.Identity.EntityFramework;
- using System.Data;
- using Microsoft.Owin.Security;
- namespace Shop2017
- {
- public partial class Login : System.Web.UI.Page
- {
- 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");
- DataSet Data = new DataSet();
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void btnSignUp_Click(object sender, EventArgs e)
- {
- Response.Redirect("register.aspx");
- }
- protected void btnLogin_Click(object sender, EventArgs e)
- {
- 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");
- var userStore = new UserStore<IdentityUser>(identityDbContext);
- var userManager = new UserManager<IdentityUser>(userStore);
- var user = userManager.Find(TextUsername.Text, txtPassword.Text);
- //Cookie attempt
- HttpCookie UserLogin = new HttpCookie("UserCookieInfo");
- UserLogin["Username"] = TextUsername.Text;
- UserLogin["Password"] = txtPassword.Text;
- UserLogin.Expires = DateTime.Now.AddDays(60);
- Response.Cookies.Add(UserLogin);
- Session["Username"] = TextUsername.Text;
- Session["Password"] = txtPassword.Text;
- if (user != null)
- {
- // Finds username
- lBLInvalid.Text = "Welcome to Bytes " + Session["Username"];
- }
- else
- {
- //Invalid credentials
- lBLInvalid.Text = "Invalid username or password.";
- }
- }
- private void LogUserIn(UserManager<IdentityUser> usermanager, IdentityUser user)
- {
- var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
- var userIdentity = usermanager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
- authenticationManager.SignIn(new AuthenticationProperties() { }, userIdentity);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement