public function validateUser($userName, $password, AuthenticationManager $authenticationManager) { ResultHelper::whenEqual($password, null, AppLabelUtil::$ERROR_USER_NOT_FOUND, HttpStatusCode::badRequest()); $user = $this->userService->validateUser($userName, $password); ResultHelper::whenEmpty($user, AppLabelUtil::$ERROR_USER_NOT_FOUND, HttpStatusCode::unauthorized()); $token = Hash::create("sha256", mcrypt_create_iv(64, MCRYPT_DEV_URANDOM), HASH_USER_TOKEN_KEY); $authenticationManager->createValidationToken($user->getId(), $user->getRole()->getName(), $token); return $this->userMapper->mapUserToDto($user, $token); }