3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php /** * Verifies that a password matches a hash. This validator requires that * function password_verify() is available (it is implemented natively * since PHP 5.5.0). */ class Zefram_Validate_PasswordVerify extends Zend_Validate_Abstract { const EMPTY_HASH = 'passwordVerifyEmptyHash'; const INVALID = 'passwordVerifyInvalid'; /** * @var string */ protected $_hash; protected $_messageTemplates = array( self::EMPTY_HASH => 'No hash was provided to match against', self::INVALID => 'The password provided is invalid', ); /** * Constructor. * * @param string|array $options * @throws Zend_Validate_Exception */ public function __construct($options = null) { if (!function_exists('password_verify')) { throw new Zend_Validate_Exception('Function password_verify() is not callable. Please upgrade to PHP 5.5 or install userland implementation. Read more at http://php.net/manual/en/function.password-verify.php'); } if (is_string($options)) { $options = array('hash' => $options); } if (is_object($options) && method_exists($options, 'toArray')) { $options = $options->toArray(); } if ($options) { $this->setOptions((array) $options); } } /** * @param array $options * @return Zefram_Validate_PasswordVerify */ public function setOptions(array $options) { foreach ($options as $key => $value) { $method = 'set' . $key; if (method_exists($this, $method)) { $this->{$method}($value); } } return $this; } /** * @param string $hash * @return Zefram_Validate_PasswordVerify */ public function setHash($hash) { $this->_hash = (string) $hash; return $this; } /** * @return string */ public function getHash() { return $this->_hash; } /** * @param string $value * @return bool */ public function isValid($value) { $value = (string) $value; $this->_setValue($value); $hash = $this->getHash(); if (empty($hash)) { $this->_error(self::EMPTY_HASH); return false; } if (!password_verify($value, $hash)) { $this->_error(self::INVALID); return false; } return true; } }
Output for 5.1.0 - 5.2.17, 7.0.0 - 7.1.0
Fatal error: Class 'Zend_Validate_Abstract' not found in /in/jffqZ on line 8
Process exited with code 255.
Output for hhvm-3.10.0 - 3.12.0
Fatal error: unknown class Zend_Validate_Abstract in /in/jffqZ on line 8
Process exited with code 255.
Output for 5.3.0 - 5.6.28
Fatal error: Class 'Zend_Validate_Abstract' not found in /in/jffqZ on line 9
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/jffqZ on line 49
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/jffqZ on line 10
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/jffqZ on line 10
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/jffqZ on line 10
Process exited with code 255.