/// <summary> /// Logs a User in and creates a Session if the User password is successfully validated /// </summary> public LoginResult Login(User user, string password, int loginSource, bool createSession = true) { _userValidationService.ValidateRoleCanLogin(user.RoleId.ToEnum <Roles>()); _userValidationService.ValidateLoginTypeCanLogin(user); ValidateUserNotLockedOut(user); if (!ValidatePassword(user, password)) { UpdateAccessFailureAndLockout(user, 10, 5); throw new Exception("Invalid Email or Password specified"); } // Set failure count to zero again ResetAccessFailure(user); // return active Session Session session = null; if (createSession) { session = _sessionService.GetOrCreateSession(user.Id, loginSource); } return(LoginResult.Get(session?.SessionGuid, user.ForcePasswordReset, !user.EmailConfirmed)); }