Ejemplo n.º 1
0
        public PartialViewResult LogIn(LogInModel logInModel)
        {
            User dbUser = null;
            if (ModelState.IsValid)
            {
                dbUser = _userBlo.GetUser(logInModel.Username);
                ValidateLogInModel(dbUser, logInModel);
            }

            if (ModelState.IsValid)
            {
                Authorize(dbUser);
            }

            return PartialView("_LogIn");
        }
Ejemplo n.º 2
0
 // Verify that user exists and password is right
 private void ValidateLogInModel(User dbUser, LogInModel logInModel)
 {
     if (dbUser == null)
     {
         ModelState.AddModelError("Username", "This username doesn't exist");
     }
     else
     {
         try
         {
             if (!BCrypt.Net.BCrypt.Verify(logInModel.Password, dbUser.Password))
             {
                 ModelState.AddModelError("Password", "Password is wrong!");
             }
         }
         catch (SaltParseException)
         {
             ModelState.AddModelError("Password", "Password is wrong!");
         }
     }
 }