1
0
Fork 0
mirror of synced 2024-06-29 19:50:26 +12:00
appwrite/src/Appwrite/Auth/Hash/Bcrypt.php

47 lines
1 KiB
PHP
Raw Normal View History

<?php
namespace Appwrite\Auth\Hash;
use Appwrite\Auth\Hash;
/*
2022-06-17 21:25:28 +12:00
* Bcrypt accepted options:
* int cost
* string? salt; auto-generated if empty
2022-06-14 23:08:54 +12:00
*
2022-06-22 01:59:52 +12:00
* Reference: https://www.php.net/manual/en/password.constants.php
*/
2022-05-15 18:53:26 +12:00
class Bcrypt extends Hash
{
/**
* @param string $password Input password to hash
2022-06-14 23:08:54 +12:00
*
* @return string hash
*/
2022-06-14 23:08:54 +12:00
public function hash(string $password): string
{
return \password_hash($password, PASSWORD_BCRYPT, $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
*
* @return boolean true if password matches hash
*/
2022-06-14 23:08:54 +12:00
public function verify(string $password, string $hash): bool
{
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-06-22 01:59:52 +12:00
public function getDefaultOptions(): array
2022-06-14 23:08:54 +12:00
{
return [ 'cost' => 8 ];
}
2022-06-14 23:08:54 +12:00
}