src/Webiny/Login/Login.php
public function validateDeviceConfirmationToken($username, $token)
    {
        $this->username = $username;

        if ($this->rateLimitReached()) {
            throw new LoginException('The current user session is block from login page.', 1);
        }

        $allowedList = $this->getMeta()->allowedDevices->val();
        if (!is_array($allowedList)) {
            return false;
        }

        $newAllowedList = $allowedList;
        $deviceId = $this->getDeviceFingerprint();
        $i = 0;
        foreach ($allowedList as $al) {
            if ($al['confirmed'] == false && $al['device'] == $deviceId && $token == $al['validationToken']) {
                $token = $this->crypt()->generateUserReadableString(32);
                $newAllowedList[$i]['confirmed'] = true;
                $newAllowedList[$i]['created'] = time();
                $newAllowedList[$i]['token'] = $token;


                $this->getMeta()->allowedDevices = $newAllowedList;
                $this->getMeta()->save();

                return $token;
            }
            $i++;
        }

        // validation cleanup (if validation was unsuccessful, we need to delete the token, a new one needs to be requested)
        $newAllowedList = [];
        foreach ($allowedList as $al) {
            if ($al['confirmed'] != false) {
                $newAllowedList[] = $al;
            }
        }
        $this->getMeta()->allowedDevices = $newAllowedList;
        $this->getMeta()->save();

        // increment login count
        $this->incrementLoginAttempts();

        return false;
    }
public function validateDeviceConfirmationToken($username, $token)
    {
        $this->username = $username;

        if ($this->rateLimitReached()) {
            throw new LoginException('The current user session is block from login page.', 1);
        }

        $allowedList = $this->getMeta()->allowedDevices->val();
        if (!is_array($allowedList)) {
            return false;
        }

        $newAllowedList = $allowedList;
        $deviceId = $this->getDeviceFingerprint();
        $i = 0;
        foreach ($allowedList as $al) {
            if ($al['confirmed'] == false && $al['device'] == $deviceId && $token == $al['validationToken']) {
                $token = $this->crypt()->generateUserReadableString(32);
                $newAllowedList[$i]['confirmed'] = true;
                $newAllowedList[$i]['created'] = time();
                $newAllowedList[$i]['token'] = $token;


                $this->getMeta()->allowedDevices = $newAllowedList;
                $this->getMeta()->save();

                return $token;
            }
            $i++;
        }

        // validation cleanup (if validation was unsuccessful, we need to delete the token, a new one needs to be requested)
        $newAllowedList = [];
        foreach ($allowedList as $al) {
            if ($al['confirmed'] != false) {
                $newAllowedList[] = $al;
            }
        }
        $this->getMeta()->allowedDevices = $newAllowedList;
        $this->getMeta()->save();

        // increment login count
        $this->incrementLoginAttempts();

        return false;
    }
public function validateDeviceConfirmationToken ( $ username , $ token ) { $ this -> username = $ username ; if ( $ this -> rateLimitReached ( ) ) { throw new LoginException ( 'The current user session is block from login page.' , 1 ) ; } $ allowedList = $ this -> getMeta ( ) -> allowedDevices -> val ( ) ; if ( ! is_array ( $ allowedList ) ) { return false ; } $ newAllowedList = $ allowedList ; $ deviceId = $ this -> getDeviceFingerprint ( ) ; $ i = 0 ; foreach ( $ allowedList as $ al ) { if ( $ al [ 'confirmed' ] == false && $ al [ 'device' ] == $ deviceId && $ token == $ al [ 'validationToken' ] ) { $ token = $ this -> crypt ( ) -> generateUserReadableString ( 32 ) ; $ newAllowedList [ $ i ] [ 'confirmed' ] = true ; $ newAllowedList [ $ i ] [ 'created' ] = time ( ) ; $ newAllowedList [ $ i ] [ 'token' ] = $ token ; $ this -> getMeta ( ) -> allowedDevices = $ newAllowedList ; $ this -> getMeta ( ) -> save ( ) ; return $ token ; } $ i ++ ; } // validation cleanup (if validation was unsuccessful, we need to delete the token, a new one needs to be requested) $ newAllowedList = [ ] ; foreach ( $ allowedList as $ al ) { if ( $ al [ 'confirmed' ] != false ) { $ newAllowedList [ ] = $ al ; } } $ this -> getMeta ( ) -> allowedDevices = $ newAllowedList ; $ this -> getMeta ( ) -> save ( ) ; // increment login count $ this -> incrementLoginAttempts ( ) ; return false ; }
Checks if the provided token matches a device validation token in the database for the given username.
If token matches, the given device is now allowed access.

@param $username
@param $token

@return bool|string
@throws LoginException
@throws \Webiny\Component\Crypt\CryptException
Checks if the provided token matches a device validation token in the database for the given username . If token matches the given device is now allowed access .