1
0
Fork 0
mirror of synced 2024-09-28 07:21:35 +12:00
appwrite/src/Appwrite/Auth/Hash.php

63 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace Appwrite\Auth;
abstract class Hash
{
/**
2022-06-22 01:59:52 +12:00
* @var array $options Hashing-algo specific options
*/
2022-06-22 01:59:52 +12:00
protected array $options = [];
2022-06-14 23:08:54 +12:00
/**
2022-06-22 01:59:52 +12:00
* @param array $options Hashing-algo specific options
*/
2022-06-22 01:59:52 +12:00
public function __construct(array $options = [])
2022-06-14 23:08:54 +12:00
{
$this->setOptions($options);
}
/**
* Set hashing algo options
2022-06-14 23:08:54 +12:00
*
2022-06-22 01:59:52 +12:00
* @param array $options Hashing-algo specific options
*/
2022-06-22 01:59:52 +12:00
public function setOptions(array $options): self
2022-06-14 23:08:54 +12:00
{
$this->options = \array_merge([], $this->getDefaultOptions(), $options);
return $this;
}
/**
* Get hashing algo options
2022-06-14 23:08:54 +12:00
*
2022-06-22 01:59:52 +12:00
* @return array $options Hashing-algo specific options
*/
2022-06-22 01:59:52 +12:00
public function getOptions(): array
2022-06-14 23:08:54 +12:00
{
return $this->options;
}
/**
* @param string $password Input password to hash
2022-06-14 23:08:54 +12: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 23:08:54 +12: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 23:08:54 +12:00
*
2022-06-22 01:59:52 +12:00
* @return array options named array
*/
2022-06-22 01:59:52 +12:00
abstract public function getDefaultOptions(): array;
}