2022-05-01 14:13:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Appwrite\Auth;
|
|
|
|
|
|
|
|
|
|
abstract class Hash
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @var mixed $options Hashing-algo specific options
|
|
|
|
|
*/
|
|
|
|
|
protected mixed $options = [];
|
2022-06-14 11:08:54 +00:00
|
|
|
|
2022-05-01 14:13:59 +00:00
|
|
|
/**
|
|
|
|
|
* @param mixed $options Hashing-algo specific options
|
|
|
|
|
*/
|
2022-06-14 11:08:54 +00:00
|
|
|
public function __construct(mixed $options = [])
|
|
|
|
|
{
|
2022-05-01 14:13:59 +00:00
|
|
|
$this->setOptions($options);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set hashing algo options
|
2022-06-14 11:08:54 +00:00
|
|
|
*
|
2022-05-01 14:13:59 +00:00
|
|
|
* @param mixed $options Hashing-algo specific options
|
|
|
|
|
*/
|
2022-06-14 11:08:54 +00:00
|
|
|
public function setOptions(mixed $options): self
|
|
|
|
|
{
|
2022-05-01 14:13:59 +00:00
|
|
|
$this->options = \array_merge([], $this->getDefaultOptions(), $options);
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get hashing algo options
|
2022-06-14 11:08:54 +00:00
|
|
|
*
|
2022-05-01 14:13:59 +00:00
|
|
|
* @return mixed $options Hashing-algo specific options
|
|
|
|
|
*/
|
2022-06-14 11:08:54 +00:00
|
|
|
public function getOptions(): mixed
|
|
|
|
|
{
|
2022-05-01 14:13:59 +00:00
|
|
|
return $this->options;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $password Input password to hash
|
2022-06-14 11:08:54 +00:00
|
|
|
*
|
2022-05-01 14:13:59 +00:00
|
|
|
* @return string hash
|
|
|
|
|
*/
|
|
|
|
|
abstract public function hash(string $password): string;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $password Input password to validate
|
|
|
|
|
* @param string $hash Hash to verify password against
|
2022-06-14 11:08:54 +00:00
|
|
|
*
|
2022-05-01 14:13:59 +00:00
|
|
|
* @return boolean true if password matches hash
|
|
|
|
|
*/
|
|
|
|
|
abstract public function verify(string $password, string $hash): bool;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get default options for specific hashing algo
|
2022-06-14 11:08:54 +00:00
|
|
|
*
|
2022-05-01 14:13:59 +00:00
|
|
|
* @return mixed options named array
|
|
|
|
|
*/
|
|
|
|
|
abstract public function getDefaultOptions(): mixed;
|
|
|
|
|
}
|