From 7c45ca4d0f9c488fefd15cfe0550088fe2749afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 4 May 2022 15:00:36 +0000 Subject: [PATCH] WIP: Hash rework --- app/config/collections.php | 7 ++++--- app/controllers/api/account.php | 2 +- src/Appwrite/Auth/Auth.php | 2 +- src/Appwrite/Auth/Hash/PlainText.php | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 2ba2365e10..bde4be0e8b 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1,5 +1,6 @@ 256, 'signed' => true, 'required' => false, - 'default' => 'bcrypt', + 'default' => Auth::DEFAULT_ALGO, 'array' => false, 'filters' => [], ], @@ -1007,10 +1008,10 @@ $collections = [ '$id' => 'hashOptions', // Configuration of hashing algorithm 'type' => Database::VAR_STRING, 'format' => '', - 'size' => 16384, + 'size' => 65535, 'signed' => true, 'required' => false, - 'default' => '{}', + 'default' => Auth::DEFAULT_ALGO_OPTIONS, 'array' => false, 'filters' => ['json'], ], diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index abbfca5e34..a2d818237c 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -50,7 +50,7 @@ App::post('/v1/account') ->param('password', '', new Password(), 'User password. Must be at least 8 chars.') ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->param('hash', Auth::DEFAULT_ALGO, new WhiteList(\array_keys(Auth::SUPPORTED_ALGOS)), 'Hashing algorithm for password. Allowed values are: \'' . \implode('\', \'', \array_keys(Auth::SUPPORTED_ALGOS)) . '\'. The default value is \'' . Auth::DEFAULT_ALGO . '\'.', true) - ->param('hashOptions', Auth::DEFAULT_ALGO_OPTIONS, new Text(16384), 'Configuration of hashing algorithm. If left empty, default configuration is used.', true) + ->param('hashOptions', Auth::DEFAULT_ALGO_OPTIONS, new Assoc(), 'Configuration of hashing algorithm. If left empty, default configuration is used.', true) ->inject('request') ->inject('response') ->inject('project') diff --git a/src/Appwrite/Auth/Auth.php b/src/Appwrite/Auth/Auth.php index e1e149889f..6dfd8f87bd 100644 --- a/src/Appwrite/Auth/Auth.php +++ b/src/Appwrite/Auth/Auth.php @@ -25,7 +25,7 @@ class Auth ]; const DEFAULT_ALGO = 'argon2'; - const DEFAULT_ALGO_OPTIONS = ['memory_cost' => 2048, 'time_cost' => 4, 'threads' => 3]; + const DEFAULT_ALGO_OPTIONS = (object) array('memory_cost' => 2048, 'time_cost' => 4, 'threads' => 3); /** * User Roles. diff --git a/src/Appwrite/Auth/Hash/PlainText.php b/src/Appwrite/Auth/Hash/PlainText.php index d61afa7386..a57c962708 100644 --- a/src/Appwrite/Auth/Hash/PlainText.php +++ b/src/Appwrite/Auth/Hash/PlainText.php @@ -5,12 +5,12 @@ namespace Appwrite\Auth\Hash; use Appwrite\Auth\Hash; /* - * Argon2 accepted options: + * PlainText accepted options: * none * * Refference: None. Simple plain text stored. */ -class Argon2 extends Hash +class PlainText extends Hash { /** * @param string $password Input password to hash