Ejemplo n.º 1
0
        public IActionResult LoginProcess(LoginForm sub)
        {
            if (ModelState.IsValid)
            {
                PasswordHasher <User> Hasher = new PasswordHasher <User>();

                User userQueried = dbContext.Users.FirstOrDefault(user => user.Email == sub.Email1);
                if (userQueried == null)
                {
                    ModelState.AddModelError("Email1", "Email and password don't match or exist.");
                    return(View("Index"));
                }
                PasswordVerificationResult matchPw = Hasher.VerifyHashedPassword(userQueried, userQueried.PwHash, sub.Password1);
                System.Console.WriteLine(matchPw);

                if (matchPw.ToString() == "Success")
                {
                    HttpContext.Session.SetInt32("userID", userQueried.Id);
                    return(RedirectToAction("Wall", controllerName: "Home"));
                }
                else
                {
                    ModelState.AddModelError("Email1", "Email and password don't match or exist.");
                    return(View("Index"));
                }
            }
            else
            {
                return(View("Index"));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Connect([FromBody] User value)
        {
            PasswordHasher <string> pw = new PasswordHasher <string>();
            User user = _context.Users.FirstOrDefault(p => p.Email == value.Email);

            if (user == null)
            {
                return(BadRequest(new Error {
                    Type = "Error", Msg = "Bad credentials"
                }));
            }
            PasswordVerificationResult verify = pw.VerifyHashedPassword(value.Email, user.Password, value.Password);

            if (verify.ToString() == "Success")
            {
                return(Ok(user));
            }
            return(BadRequest(new Error {
                Type = "Error", Msg = "Bad credentials"
            }));
        }