예제 #1
0
        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"));
        }
예제 #2
0
        public async Task <IActionResult> Create(User user)
        {
            if (ModelState.IsValid)
            {
                // Manual Auth is custom class to hold hash methods
                user.Password = ManualAuth.Sha256(user.Password);
                // Add user and save changes to database.
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Welcome)));
            }
            return(View(user));
        }
예제 #3
0
        public async Task <IActionResult> Create(User user)
        {
            if (ModelState.IsValid)
            {
                // Hash the password
                user.Password = ManualAuth.Sha256(user.Password);
                // Now add.
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Welcome)));
            }
            return(View(user));
        }
예제 #4
0
        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"));
        }