1
0
Fork 0
mirror of synced 2024-09-29 08:51:28 +13:00
appwrite/src/Appwrite/Auth/Hash/Argon2.php

48 lines
1.1 KiB
PHP
Raw Normal View History

2022-05-05 02:37:37 +12:00
<?php
namespace Appwrite\Auth\Hash;
use Appwrite\Auth\Hash;
/*
* Argon2 accepted options:
* int threads
* int time_cost
* int memory_cost
2022-06-14 23:08:54 +12:00
*
2022-06-22 01:59:52 +12:00
* Reference: https://www.php.net/manual/en/function.password-hash.php#example-983
2022-05-05 02:37:37 +12:00
*/
class Argon2 extends Hash
{
/**
* @param string $password Input password to hash
2022-06-14 23:08:54 +12:00
*
2022-05-05 02:37:37 +12:00
* @return string hash
*/
2022-06-14 23:08:54 +12:00
public function hash(string $password): string
{
2022-05-05 02:37:37 +12:00
return \password_hash($password, PASSWORD_ARGON2ID, $this->getOptions());
}
/**
* @param string $password Input password to validate
* @param string $hash Hash to verify password against
2022-06-14 23:08:54 +12:00
*
2022-05-05 02:37:37 +12:00
* @return boolean true if password matches hash
*/
2022-06-14 23:08:54 +12:00
public function verify(string $password, string $hash): bool
{
2022-05-05 02:37:37 +12:00
return \password_verify($password, $hash);
}
/**
* 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-05-05 02:37:37 +12:00
*/
2022-06-22 01:59:52 +12:00
public function getDefaultOptions(): array
2022-06-14 23:08:54 +12:00
{
2022-06-15 20:11:48 +12:00
return ['memory_cost' => 65536, 'time_cost' => 4, 'threads' => 3];
2022-05-05 02:37:37 +12:00
}
2022-06-14 23:08:54 +12:00
}