diff options
author | Marc Alexander <admin@m-a-styles.de> | 2019-07-26 18:20:32 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2019-07-26 18:20:32 +0200 |
commit | 33be961aa0ce0aaa212705fc6ae799379dda5b4d (patch) | |
tree | 82f4760ba8d20689fcda0cbbe8e8b6c41d1b770e /phpBB/phpbb/passwords/driver/base_native.php | |
parent | c382536f47092f3afc3e283b8bfb4f23f4a0abd1 (diff) | |
parent | a4a5b069ec60bda85b3f5ef9a0c317f2b173ad27 (diff) | |
download | forums-33be961aa0ce0aaa212705fc6ae799379dda5b4d.tar forums-33be961aa0ce0aaa212705fc6ae799379dda5b4d.tar.gz forums-33be961aa0ce0aaa212705fc6ae799379dda5b4d.tar.bz2 forums-33be961aa0ce0aaa212705fc6ae799379dda5b4d.tar.xz forums-33be961aa0ce0aaa212705fc6ae799379dda5b4d.zip |
Merge pull request #5565 from JoshyPHP/ticket/16016
[ticket/16016] Add a base class for native password hashing
Diffstat (limited to 'phpBB/phpbb/passwords/driver/base_native.php')
-rw-r--r-- | phpBB/phpbb/passwords/driver/base_native.php | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/phpBB/phpbb/passwords/driver/base_native.php b/phpBB/phpbb/passwords/driver/base_native.php new file mode 100644 index 0000000000..87498327f9 --- /dev/null +++ b/phpBB/phpbb/passwords/driver/base_native.php @@ -0,0 +1,75 @@ +<?php +/** +* +* This file is part of the phpBB Forum Software package. +* +* @copyright (c) phpBB Limited <https://www.phpbb.com> +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +namespace phpbb\passwords\driver; + +abstract class base_native extends base +{ + /** + * Return the constant name for this driver's algorithm + * + * @link https://www.php.net/manual/en/password.constants.php + * + * @return string + */ + abstract public function get_algo_name(); + + /** + * Return the options set for this driver instance + * + * @return array + */ + abstract public function get_options(); + + /** + * {@inheritdoc} + */ + public function check($password, $hash, $user_row = []) + { + return password_verify($password, $hash); + } + + /** + * Return the value for this driver's algorithm + * + * @return integer + */ + public function get_algo_value() + { + return constant($this->get_algo_name()); + } + + /** + * {@inheritdoc} + */ + public function hash($password) + { + return password_hash($password, $this->get_algo_value(), $this->get_options()); + } + + /** + * {@inheritdoc} + */ + public function is_supported() + { + return defined($this->get_algo_name()) && function_exists('password_hash') && function_exists('password_needs_rehash') && function_exists('password_verify'); + } + + /** + * {@inheritdoc} + */ + public function needs_rehash($hash) + { + return password_needs_rehash($hash, $this->get_algo_value(), $this->get_options()); + } +} |