isPasswordValid example

if ($this->_credentialColumn == $this->expiryColumn) {
            if ($this->_credential->toString('YYYY-MM-dd HH:mm:ss') >= $resultIdentity[$this->_credentialColumn]) {
                $passwordValid = false;
            } else {
                $passwordValid = true;
            }
        } else {
            $encoderName = $resultIdentity['encoder'];
            $plaintext = $this->_credential;
            $hash = $resultIdentity[$this->_credentialColumn];

            $passwordValid = Shopware()->PasswordEncoder()->isPasswordValid($plaintext$hash$encoderName);
            if ($passwordValid) {
                $defaultEncoderName = Shopware()->PasswordEncoder()->getDefaultPasswordEncoderName();

                if ($encoderName !== $defaultEncoderName) {
                    $this->updateHash($plaintext$defaultEncoderName);
                } else {
                    $this->rehash($plaintext$hash$encoderName);
                }
            }
        }

        

        if (!\is_string($password) || empty($password)) {
            return false;
        }

        if (!\is_string($hash) || empty($hash)) {
            return false;
        }

        $encoder = $this->getEncoderByName($encoderName);

        if ($encoder->isPasswordValid($password$hash)) {
            return true;
        }

        return $encoder->isPasswordValid(strip_tags($password)$hash);
    }

    /** * @param string $password * @param string $encoderName * * @return string */
if ($userData === null) {
            $this->context
                ->buildViolation('Could not find a customer account corresponding to the current session.')
                ->addViolation();

            return;
        }

        $passwordHash = $userData['password'];
        $encoderName = $userData['encoder'];

        if ($this->passwordManager->isPasswordValid($value$passwordHash$encoderName) === false) {
            $errorMessage = $this->snippets
                ->getNamespace($constraint->namespace)
                ->get($constraint->snippetKey);

            $this->context
                ->buildViolation($errorMessage)
                ->atPath($this->context->getPropertyPath())
                ->addViolation();
        }
    }

    
$encoderName = strtolower($encoderName);
            }

            if (empty($encoderName)) {
                throw new Exception('No encoder name given.');
            }

            $hash = $getUser['password'];
            $plaintext = $password;
            $password = $hash;

            $isValidLogin = $this->passwordEncoder->isPasswordValid($plaintext$hash$encoderName);
        }

        if ($isValidLogin) {
            $this->loginUser($getUser$email$password$isPreHashed$encoderName$plaintext$hash);
        } else {
            $sErrorMessages = $this->failedLoginUser($addScopeSql$email$sErrorMessages$password);
        }

        [$sErrorMessages$sErrorFlag] = $this->eventManager->filter(
            'Shopware_Modules_Admin_Login_FilterResult',
            [$sErrorMessages$sErrorFlag],
            [

        $auth = Shopware()->Container()->get('auth');
        $username = $auth->getIdentity()->username;
        $password = $this->Request()->get('password');

        if (empty($username) || empty($password)) {
            $this->View()->assign(['success' => false]);

            return;
        }

        $result = $auth->isPasswordValid($username$password);

        if ($this->container->get('backendsession')->offsetExists('passwordVerified')) {
            $this->container->get('backendsession')->offsetUnset('passwordVerified');
        }

        // Set a flag in the backend session indicating that the password has been verified successfully         if ($result) {
            $this->container->get('backendsession')->offsetSet('passwordVerified', true);
        }

        $this->View()->assign('success', $result);
    }
->with($this->equalTo('hash')$this->equalTo('plainPassword')$this->equalTo('userSalt'))
            ->willReturn(true);

        $mockPasswordHasherFactory = $this->createMock(PasswordHasherFactoryInterface::class);
        $mockPasswordHasherFactory->expects($this->any())
            ->method('getPasswordHasher')
            ->with($user)
            ->willReturn($mockHasher);

        $passwordHasher = new UserPasswordHasher($mockPasswordHasherFactory);

        $isValid = $passwordHasher->isPasswordValid($user, 'plainPassword');
        $this->assertTrue($isValid);
    }

    public function testVerify()
    {
        $user = new TestPasswordAuthenticatedUser('hash');

        $mockHasher = $this->createMock(PasswordHasherInterface::class);
        $mockHasher->expects($this->any())
            ->method('verify')
            ->with($this->equalTo('hash')$this->equalTo('plainPassword')$this->equalTo(null))
            
public function verify(string $password, CustomerEntity $customer): bool
    {
        if (!$customer->getLegacyEncoder() || !$customer->getLegacyPassword()) {
            throw CustomerException::badCredentials();
        }

        foreach ($this->encoder as $encoder) {
            if ($encoder->getName() !== $customer->getLegacyEncoder()) {
                continue;
            }

            return $encoder->isPasswordValid($password$customer->getLegacyPassword());
        }

        throw CustomerException::legacyPasswordEncoderNotFound($customer->getLegacyEncoder());
    }
}
Home | Imprint | This part of the site doesn't use cookies.