aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/passwords/driver/base_native.php
blob: ab2e9f83a4533c19e92e268be8f38845893c76c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?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());
	}

	/**
	* Check if Sodium implementation for argon2 algorithm is being used
	*
	* @link https://wiki.php.net/rfc/sodium.argon.hash
	*
	* @return bool
	*/
	public function is_sodium()
	{
		static $is_sodium;

		if (!isset($is_sodium))
		{
			$is_sodium = defined('PASSWORD_ARGON2_PROVIDER') && PASSWORD_ARGON2_PROVIDER == 'sodium';
		}

		return $is_sodium;
	}

	/**
	* {@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());
	}
}