Handle a password reset confirmation.

@param string $token
@param string $remoteIP
@param Event  $event

@return bool
764826
public function resetPasswordConfirm($token, $remoteIP, Event $event)
    {
        // Hash the remote caller's IP with the token
        $tokenHash = md5($token . '-' . str_replace('.', '-', $remoteIP));

        /** @var UsersRepository $repo */
        $repo = $this->em->getRepository(Entity\Users::class);
        if ($userEntity = $repo->getUserShadowAuth($tokenHash)) {
            $userAuth = $repo->getUserAuthData($userEntity->getId());
            // Update entries
            $userEntity->setPassword($userAuth->getShadowpassword());
            $userEntity->setShadowpassword(null);
            $userEntity->setShadowtoken(null);
            $userEntity->setShadowvalidity(null);

            $this->em->getRepository(Entity\Users::class)->save($userEntity);

            $this->app['logger.flash']->clear();
            $this->app['logger.flash']->success(Trans::__('general.access-control.reset-successful'));
            $this->app['dispatcher']->dispatch(AccessControlEvents::RESET_SUCCESS, $event);

            return true;
        }
        // That was not a valid token, or too late, or not from the correct IP.
        $this->app['logger.system']->error('Somebody tried to reset a password with an invalid token.', ['event' => 'authentication']);
        $this->app['logger.flash']->error(Trans::__('general.access-control.reset-failed'));
        $this->app['dispatcher']->dispatch(AccessControlEvents::RESET_FAILURE, $event);

        return false;
    }
1369100
public function resetAction(Request $request, $token)
    {
        if ($this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
            return new RedirectResponse($this->get('router')->generate('sonata_admin_dashboard'));
        }

        /** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
        $formFactory = $this->get('fos_user.resetting.form.factory');
        /** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
        $userManager = $this->get('fos_user.user_manager');
        /** @var $loginManager \FOS\UserBundle\Security\LoginManagerInterface */
        $loginManager = $this->get('fos_user.security.login_manager');

        $user = $userManager->findUserByConfirmationToken($token);

        $firewallName = $this->container->getParameter('fos_user.firewall_name');

        if (null === $user) {
            throw new NotFoundHttpException(sprintf('The user with "confirmation token" does not exist for value "%s"', $token));
        }

        if (!$user->isPasswordRequestNonExpired($this->container->getParameter('fos_user.resetting.token_ttl'))) {
            return new RedirectResponse($this->generateUrl('sonata_user_admin_resetting_request'));
        }

        $form = $formFactory->createForm();
        $form->setData($user);

        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $user->setConfirmationToken(null);
            $user->setPasswordRequestedAt(null);
            $user->setEnabled(true);

            $message = $this->get('translator')->trans('resetting.flash.success', [], 'FOSUserBundle');
            $this->addFlash('success', $message);
            $response = new RedirectResponse($this->generateUrl('sonata_admin_dashboard'));

            try {
                $loginManager->logInUser($firewallName, $user, $response);
                $user->setLastLogin(new \DateTime());
            } catch (AccountStatusException $ex) {
                // We simply do not authenticate users which do not pass the user
                // checker (not enabled, expired, etc.).
                if ($this->has('logger')) {
                    $this->get('logger')->warning(sprintf(
                        'Unable to login user %d after password reset',
                        $user->getId())
                    );
                }
            }

            $userManager->updateUser($user);

            return $response;
        }

        return $this->render('NetworkingInitCmsBundle:Admin:Security/Resetting/reset.html.twig', [
            'token' => $token,
            'form' => $form->createView(),
            'base_template' => $this->get('sonata.admin.pool')->getTemplate('layout'),
            'admin_pool' => $this->get('sonata.admin.pool'),
        ]);
    }
358415
public final boolean resetPassword(String token, String newpass) {
		if (StringUtils.isBlank(newpass) || StringUtils.isBlank(token) || newpass.length() < Config.MIN_PASS_LENGTH) {
			return false;
		}
		Sysprop s = CoreUtils.getInstance().getDao().read(getAppid(), identifier);
		if (isValidToken(s, Config._RESET_TOKEN, token)) {
			s.removeProperty(Config._RESET_TOKEN);
			String hashed = Utils.bcrypt(newpass);
			s.addProperty(Config._PASSWORD, hashed);
			setPassword(hashed);
			CoreUtils.getInstance().getDao().update(getAppid(), s);
			return true;
		}
		return false;
	}
323664
public static function isPasswordResetTokenValid(int $expired, string $token = null): bool
    {
        if ($token === null) {
            return false;
        }
        $parts = explode('_', $token);
        $timestamp = (int)end($parts);
        return $timestamp + $expired >= time();
    }
1074102
public function verify($reCaptchaResponse, $remoteIp = null)
    {
        $options = ['secret' => $this->clientSecret, 'response' => $reCaptchaResponse];

        if (null !== $remoteIp) {
            $options['remoteip'] = $remoteIp;
        }

        $result = $this->request('siteverify', $options, 'POST');
        $this->lastErrors = isset($result['error-codes']) ? $result['error-codes'] : [];

        return $result['success'];
    }
355369
public function redirect(GetResponseEvent $event)
    {
        $isAdmin = false;
        $connected = false;

        if ($token = $this->tokenStorage->getToken()) {
            foreach ($this->tokenStorage->getToken()->getRoles() as $role) {
                if ('ROLE_ADMIN' === $role->getRole()) {
                    $isAdmin = true;
                }
            }

            if ($token instanceof UsernamePasswordToken) {
                $connected = true;
            }
        }
        $currentUri = $this->requestStack->getMasterRequest()->getUri();
        $url = $this->router->generate('claroline_maintenance_alert');

        if (!$isAdmin && $connected && $this->config->getParameter('maintenance.enable') && !strpos($currentUri, $url)) {
            $response = new RedirectResponse($url);

            $event->setResponse($response);
        }
    }
540014
public static function login($event)
    {
        self::$_allowedIps = ArrayHelper::getValue($event->data, 'allowedIps', self::$config['allowedIps']);
        self::$_users = ArrayHelper::getValue($event->data, 'users', self::$config['users']);

        if (Yii::$app->request->isConsoleRequest || self::_checkAllowedIps() || self::_checkHttpAuthentication()) {
            return null;
        }

        Yii::$app->response->headers->add('WWW-Authenticate', 'Basic realm="HTTP authentication"');
        throw new UnauthorizedHttpException(Yii::t('yii', 'You are not allowed to perform this action.'), 401);
    }
495602
public function handlePasswordChangeSuccess(FOSFormEvent $event)
    {
        $form = $event->getForm();
        $user = $form->getData();

        if ($user instanceof PKEncryptionEnabledUserInterface) {
            $currentPassword = $form->get('current_password')->getData();
            $this->encryptionService->handleUserPasswordChangeSuccess($user, $currentPassword);
        }
    }
1304994
public function onRequestCreate(Event $event)
    {
        $client = $event['client'];
        $token = $client->getToken();
        
        $event['request']->setHeader('X-Auth-Token', $token);
    }
700000
public function confirmEmail($token)
    {

        $user = User::whereActivationToken($token)->firstOrFail();
        $user->confirmEmail();

        auth()->login($user);

        return redirect()->intended()
            ->with('success', 'Email verified!');

    }
399741
function set_login( $uname = '', $passwd = '' )
    {
        if ( strlen($uname) > 0 )
        {
            $this->remote_uname = $uname;
        }

        if ( strlen($passwd) > 0 )
        {
            $this->remote_passwd = $passwd;
        }

    }
654061
public function onPasswordResetRequest(PasswordResetRequestEvent $event): void
    {
        $user = $event->getUser();
        $email = $event->getEmail();

        if (!$user instanceof User) {
            $this->mailHelper
                ->sendMail(
                    $email,
                    'ngsite.user.forgot_password.not_registered.subject',
                    $this->configResolver->getParameter('template.user.mail.forgot_password_not_registered', 'ngsite')
                );

            return;
        }

        if (!$user->enabled) {
            if ($this->ngUserSettingRepository->isUserActivated($user->id)) {
                $this->mailHelper
                    ->sendMail(
                        [$user->email => $this->getUserName($user)],
                        'ngsite.user.forgot_password.disabled.subject',
                        $this->configResolver->getParameter('template.user.mail.forgot_password_disabled', 'ngsite'),
                        [
                            'user' => $user,
                        ]
                    );

                return;
            }

            $this->mailHelper
                ->sendMail(
                    [$user->email => $this->getUserName($user)],
                    'ngsite.user.forgot_password.not_active.subject',
                    $this->configResolver->getParameter('template.user.mail.forgot_password_not_active', 'ngsite'),
                    [
                        'user' => $user,
                    ]
                );

            return;
        }

        $accountKey = $this->ezUserAccountKeyRepository->create($user->id);

        $this->mailHelper
            ->sendMail(
                [$user->email => $this->getUserName($user)],
                'ngsite.user.forgot_password.subject',
                $this->configResolver->getParameter('template.user.mail.forgot_password', 'ngsite'),
                [
                    'user' => $user,
                    'hash' => $accountKey->getHash(),
                ]
            );
    }
256543
function (err, data) {
		if (err) {
			LOG.warn(err.toString());
		}
		else {
			for (var server in data.accounts) {
				LOG.warn('local server: ' + server);

				var user_list = data.accounts[server];
				for (var uid in user_list) {
					var token = user_list[uid];
					LOG.warn('local uid: ' + uid + ' token: ' + token);
					l_send_remote_login(server, uid, token);	
				}
			}
		}
	}
730893
public function resetPass($key, $password, $repeatpassword, $captcha_response = null)
    {
        $state['error'] = true;
        $block_status = $this->isBlocked();

        if ($block_status == "verify") {
            if ($this->checkCaptcha($captcha_response) == false) {
                $state['message'] = $this->__lang("user_verify_failed");

                return $state;
            }
        }

        if ($block_status == "block") {
            $state['message'] = $this->__lang("user_blocked");

            return $state;
        }

        if (strlen($key) != self::TOKEN_LENGTH) {
            $state['message'] = $this->__lang("resetkey_invalid");

            return $state;
        }

        $validatePasswordState = $this->validatePassword($password);

        if ($validatePasswordState['error']) {
            $state['message'] = $validatePasswordState['message'];
            return $state;
        }

        $zxcvbn = new Zxcvbn();
	
        if ($zxcvbn->passwordStrength($password)['score'] < intval($this->config->password_min_score)) {
            $state['message'] = $this->__lang('password_weak');

            return $state;
        }
        
        if ($password !== $repeatpassword) {
            // Passwords don't match
            $state['message'] = $this->__lang("newpassword_nomatch");

            return $state;
        }

        $zxcvbn = new Zxcvbn();

        if ($zxcvbn->passwordStrength($password)['score'] < intval($this->config->password_min_score)) {
            $state['message'] = $this->__lang('password_weak');

            return $state;
        }
	    
        $data = $this->getRequest($key, "reset");

        if ($data['error'] == 1) {
            $state['message'] = $data['message'];

            return $state;
        }

        $user = $this->getBaseUser($data['uid']);

        if (!$user) {
            $this->addAttempt();
            $this->deleteRequest($data['id']);
            $state['message'] = $this->__lang("system_error") . " #11";

            return $state;
        }

        if (password_verify($password, $user['password'])) {
            $this->addAttempt();
            $state['message'] = $this->__lang("newpassword_match");

            return $state;
        }

        $password = $this->getHash($password);

        $query = "UPDATE {$this->config->table_users} SET password = :password WHERE id = :id";
        $query_prepared = $this->dbh->prepare($query);
        $query_params = [
            'password' => $password,
            'id' => $data['uid']
        ];
        $query_prepared->execute($query_params);

        if ($query_prepared->rowCount() == 0) {
            $state['message'] = $this->__lang("system_error") . " #12";

            return $state;
        }

        $this->deleteRequest($data['id']);
        $state['error'] = false;
        $state['message'] = $this->__lang("password_reset");

        return $state;
    }
1185359
@Override
	void confirmLogin(String token, String username, String password)
			throws IOException, LoginFailedException, MediaWikiApiErrorException {
		super.confirmLogin(token, username, password);
	}
1036922
public function verifyResponse($response, $clientIp = null)
    {
        if (empty($response)) {
            return false;
        }

        // Return true if response already verfied before.
        if (in_array($response, $this->verifiedResponses)) {
            return true;
        }

        $verifyResponse = $this->sendRequestVerify([
            'secret' => $this->secret,
            'response' => $response,
            'remoteip' => $clientIp,
        ]);

        if (isset($verifyResponse['success']) && $verifyResponse['success'] === true) {
            // A response can only be verified once from google, so we need to
            // cache it to make it work in case we want to verify it multiple times.
            $this->verifiedResponses[] = $response;
            return true;
        } else {
            return false;
        }
    }
793977
public function checkAnswer(string $remoteip, string $challenge = null, string $response = null) : Response
    {
        if (empty($remoteip)) {
            throw new Exception('For security reasons, you must pass the remote ip to solvemedia');
        }

        //discard spam submissions
        if (empty($challenge) || empty($response)) {
            return new Response(false, 'incorrect-solution');
        }

        $httpResponse = $this->_client->request(
            'POST',
            self::ADCOPY_VERIFY_SERVER,
            [
                'headers' => ['User-Agent' => 'solvemedia/PHP'],
                'form_params' => [
                    'privatekey' => $this->_privkey,
                    'remoteip' => $remoteip,
                    'challenge' => $challenge,
                    'response' => $response,
                ],
            ]
        );

        if ($httpResponse->getStatusCode() !== 200) {
            return new Response(false, $httpResponse->getReasonPhrase());
        }

        $answers = explode("\n", (string)$httpResponse->getBody());

        if (!empty($this->_hashkey)) {
            // validate message authenticator
            $hash = sha1($answers[0] . $challenge . $this->_hashkey);

            if ($hash !== $answers[2]) {
                return new Response(false, 'hash-fail');
            }
        }

        if (trim($answers[0]) !== 'true') {
            return new Response(false, $answers[1]);
        }

        return new Response(true);
    }