public async Task <IActionResult> Login(User user) { CookieOptions cookieOptions = new CookieOptions(); cookieOptions.Expires = new DateTimeOffset(DateTime.Now.AddDays(7)); if (ModelState.IsValid) { // attempt to get a user with the matching username from DB. User GetUser = await _context.Users.SingleOrDefaultAsync(u => u.UserName == user.UserName); // if no match on username skip password check. if (GetUser != null) { // compare hashed passwords. if (ManualAuth.Sha256Check(user.Password, GetUser.Password)) { // if password match is true return treats. HttpContext.Response.Cookies.Append("user_id", user.Id.ToString(), cookieOptions); return(View(nameof(Index))); } } } return(View("LoginFail")); }
public async Task <IActionResult> Login(User user) { if (ModelState.IsValid) { // attempt to get a user with the matching username from DB. User GetUser = await _context.Users.SingleOrDefaultAsync(u => u.UserName == user.UserName); // if no match on username skip password check. if (GetUser != null) { // compare hashed passwords. if (ManualAuth.Sha256Check(user.Password, GetUser.Password)) { // if password match is true return treats. return(View("Treats")); } } } return(View("LoginFail")); }