Skip to content

Instantly share code, notes, and snippets.

@jp1987
Created March 5, 2013 09:39
Show Gist options
  • Save jp1987/5089105 to your computer and use it in GitHub Desktop.
Save jp1987/5089105 to your computer and use it in GitHub Desktop.
<?php
namespace My\App\Validation\Validator;
use TYPO3\Flow\Annotations as Flow;
/**
* Checks if the specified password matches the current user's password
*
* @Flow\Scope("singleton")
*/
class CurrentPasswordValidator extends \TYPO3\Flow\Validation\Validator\AbstractValidator {
/**
* @Flow\Inject
* @var \TYPO3\Flow\Security\Context
*/
protected $securityContext;
/**
* @var \TYPO3\Flow\Security\Cryptography\HashService
* @Flow\Inject
*/
protected $hashService;
/**
* @param mixed $value The value that should be validated
* @return void
*/
protected function isValid($value) {
$account = $this->securityContext->getPartyByType('\My\App\Domain\Model\User\User');
$accounts = $account->getAccounts();
if (!($this->hashService->validatePassword($value, $accounts->first()->getCredentialsSource()))) {
$this->addError('Current password is not correct', 1345976880);
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment