Fix snake_case

This commit is contained in:
Matej Bačo committed 2022-06-16 09:21:35 +00:00
1 parent 797bdda405
commit 0aaee54a63
9 files changed
+35 -35

No files matched your search

+4 -4
View File
@@ -273,15 +273,15 @@ App::post('/v1/users/import/scrypt')
}
if (!empty($passwordCpu)) {
$options['cost_cpu'] = $passwordCpu;
$options['costCpu'] = $passwordCpu;
}
if (!empty($passwordMemory)) {
$options['cost_memory'] = $passwordMemory;
$options['costMemory'] = $passwordMemory;
}
if (!empty($passwordParallel)) {
$options['cost_parallel'] = $passwordParallel;
$options['costParallel'] = $passwordParallel;
}
if (!empty($passwordLength)) {
@@ -318,7 +318,7 @@ App::post('/v1/users/import/scrypt-modified')
->inject('usage')
->inject('events')
->action(function (string $userId, string $email, string $password, string $passwordSalt, string $passwordSaltSeparator, string $passwordSignerKey, string $name, Response $response, Database $dbForProject, Stats $usage, Event $events) {
$user = createUser('scrypt_mod', '{"signer_key":"' . $passwordSignerKey . '","salt_separator":"' . $passwordSaltSeparator . '","salt":"' . $passwordSalt . '"}', $userId, $email, $password, $name, $dbForProject, $usage, $events);
$user = createUser('scryptMod', '{"signerKey":"' . $passwordSignerKey . '","saltSeparator":"' . $passwordSaltSeparator . '","salt":"' . $passwordSalt . '"}', $userId, $email, $password, $name, $dbForProject, $usage, $events);
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic($user, Response::MODEL_USER);
+4 -4
View File
@@ -21,12 +21,12 @@ class Auth
'sha',
'phpass',
'scrypt',
'scrypt_mod',
'scryptMod',
'plaintext'
];
public const DEFAULT_ALGO = 'argon2';
public const DEFAULT_ALGO_OPTIONS = ['memory_cost' => 2048, 'time_cost' => 4, 'threads' => 3];
public const DEFAULT_ALGO_OPTIONS = ['memoryCost' => 2048, 'timeCost' => 4, 'threads' => 3];
/**
* User Roles.
@@ -194,7 +194,7 @@ class Auth
$hasher = new Scrypt($options);
return $hasher->hash($string);
break;
case 'scrypt_mod':
case 'scryptMod':
$hasher = new Scryptmodified($options);
return $hasher->hash($string);
break;
@@ -250,7 +250,7 @@ class Auth
$hasher = new Scrypt($options);
return $hasher->verify($plain, $hash);
break;
case 'scrypt_mod':
case 'scryptMod':
$hasher = new Scryptmodified($options);
return $hasher->verify($plain, $hash);
break;
+5 -5
View File
@@ -7,9 +7,9 @@ use Appwrite\Auth\Hash;
/*
* SCrypt accepted options:
* string? salt; auto-generated if empty
* int cost_cpu
* int cost_memory
* int cost_parallel
* int costCpu
* int costMemory
* int costParallel
* int length
*
* Refference: https://github.com/DomBlack/php-scrypt/blob/master/scrypt.php#L112-L116
@@ -25,7 +25,7 @@ class Scrypt extends Hash
{
$options = $this->getOptions();
return \scrypt($password, $options['salt'] ?? null, $options['cost_cpu'], $options['cost_memory'], $options['cost_parallel'], $options['length']);
return \scrypt($password, $options['salt'] ?? null, $options['costCpu'], $options['costMemory'], $options['costParallel'], $options['length']);
}
/**
@@ -46,6 +46,6 @@ class Scrypt extends Hash
*/
public function getDefaultOptions(): mixed
{
return [ 'cost_cpu' => 8, 'cost_memory' => 14, 'cost_parallel' => 1, 'length' => 64 ];
return [ 'costCpu' => 8, 'costMemory' => 14, 'costParallel' => 1, 'length' => 64 ];
}
}
+4 -4
View File
@@ -8,8 +8,8 @@ use Appwrite\Auth\Hash;
* This is SCrypt hash with some additional steps added by Google.
*
* string salt
* string salt_separator
* strin signer_key
* string saltSeparator
* strin signerKey
*
* Refference: https://github.com/DomBlack/php-scrypt/blob/master/scrypt.php#L112-L116
*/
@@ -25,7 +25,7 @@ class Scryptmodified extends Hash
$options = $this->getOptions();
$derivedKeyBytes = $this->generateDerivedKey($password);
$signerKeyBytes = \base64_decode($options['signer_key']);
$signerKeyBytes = \base64_decode($options['signerKey']);
$hashedPassword = $this->hashKeys($signerKeyBytes, $derivedKeyBytes);
@@ -58,7 +58,7 @@ class Scryptmodified extends Hash
$options = $this->getOptions();
$saltBytes = \base64_decode($options['salt']);
$saltSeparatorBytes = \base64_decode($options['salt_separator']);
$saltSeparatorBytes = \base64_decode($options['saltSeparator']);
$derivedKey = \scrypt(\utf8_encode($password), $saltBytes . $saltSeparatorBytes, 16384, 8, 1, 64, true);
@@ -11,13 +11,13 @@ class AlgoArgon2 extends Model
{
// No options if imported. If hashed by Appwrite, followign configuration is available:
$this
->addRule('memory_cost', [
->addRule('memoryCost', [
'type' => self::TYPE_INTEGER,
'description' => 'Memory that may be used to compute hash.',
'default' => '',
'example' => 65536,
])
->addRule('time_cost', [
->addRule('timeCost', [
'type' => self::TYPE_INTEGER,
'description' => 'Amount of time it may take to compute hash.',
'default' => '',
@@ -10,19 +10,19 @@ class AlgoScrypt extends Model
public function __construct()
{
$this
->addRule('cost_cpu', [
->addRule('costCpu', [
'type' => self::TYPE_INTEGER,
'description' => 'CPU complexity of computed hash.',
'default' => '',
'example' => 8,
])
->addRule('cost_memory', [
->addRule('costMemory', [
'type' => self::TYPE_INTEGER,
'description' => 'Memory complexity of computed hash.',
'default' => '',
'example' => 14,
])
->addRule('cost_parallel', [
->addRule('costParallel', [
'type' => self::TYPE_INTEGER,
'description' => 'Parallelization of computed hash.',
'default' => '',
@@ -16,13 +16,13 @@ class AlgoScryptModified extends Model
'default' => '',
'example' => 'UxLMreBr6tYyjQ==',
])
->addRule('salt_separator', [
->addRule('saltSeparator', [
'type' => self::TYPE_STRING,
'description' => 'Separator used to compute hash.',
'default' => '',
'example' => 'Bw==',
])
->addRule('signer_key', [
->addRule('signerKey', [
'type' => self::TYPE_STRING,
'description' => 'Key used to compute hash.',
'default' => '',
+6 -6
View File
@@ -131,9 +131,9 @@ trait UsersBase
$this->assertEquals($res['body']['password'], '3fdef49701bc4cfaacd551fe017283513284b4731e6945c263246ef948d3cf63b5d269c31fd697246085111a428245e24a4ddc6b64c687bc60a8910dbafc1d5b');
$this->assertEquals($res['body']['hash'], 'scrypt');
$this->assertEquals($res['body']['hashOptions']['salt'], 'appwrite');
$this->assertEquals($res['body']['hashOptions']['cost_cpu'], 16384);
$this->assertEquals($res['body']['hashOptions']['cost_memory'], 13);
$this->assertEquals($res['body']['hashOptions']['cost_parallel'], 2);
$this->assertEquals($res['body']['hashOptions']['costCpu'], 16384);
$this->assertEquals($res['body']['hashOptions']['costMemory'], 13);
$this->assertEquals($res['body']['hashOptions']['costParallel'], 2);
$this->assertEquals($res['body']['hashOptions']['length'], 64);
$res = $this->client->call(Client::METHOD_POST, '/users/import/phpass', array_merge([
@@ -164,10 +164,10 @@ trait UsersBase
$this->assertEquals($res['headers']['status-code'], 201);
$this->assertEquals($res['body']['password'], 'UlM7JiXRcQhzAGlaonpSqNSLIz475WMddOgLjej5De9vxTy48K6WtqlEzrRFeK4t0COfMhWCb8wuMHgxOFCHFQ==');
$this->assertEquals($res['body']['hash'], 'scrypt_mod');
$this->assertEquals($res['body']['hash'], 'scryptMod');
$this->assertEquals($res['body']['hashOptions']['salt'], 'UxLMreBr6tYyjQ==');
$this->assertEquals($res['body']['hashOptions']['signer_key'], 'XyEKE9RcTDeLEsL/RjwPDBv/RqDl8fb3gpYEOQaPihbxf1ZAtSOHCjuAAa7Q3oHpCYhXSN9tizHgVOwn6krflQ==');
$this->assertEquals($res['body']['hashOptions']['salt_separator'], 'Bw==');
$this->assertEquals($res['body']['hashOptions']['signerKey'], 'XyEKE9RcTDeLEsL/RjwPDBv/RqDl8fb3gpYEOQaPihbxf1ZAtSOHCjuAAa7Q3oHpCYhXSN9tizHgVOwn6krflQ==');
$this->assertEquals($res['body']['hashOptions']['saltSeparator'], 'Bw==');
return ['userId' => $body['$id']];
}
+5 -5
View File
@@ -120,7 +120,7 @@ class AuthTest extends TestCase
$hash = '2bc477f4160e7dc0e6bc6849ffa38a7062fec3800d937ce251cdf552609b94919c623cd07cc36ad600bc8caea8399e6f815a6d7ed96995d495ed70890d359d6d';
$generatedHash = Auth::passwordHash($plain, 'scrypt');
$this->assertEquals(true, Auth::passwordVerify($plain, $generatedHash, 'scrypt'));
$this->assertEquals(true, Auth::passwordVerify($plain, $hash, 'scrypt', ['length' => 64, 'cost_cpu' => 16384, 'cost_memory' => 12, 'cost_parallel' => 2]));
$this->assertEquals(true, Auth::passwordVerify($plain, $hash, 'scrypt', ['length' => 64, 'costCpu' => 16384, 'costMemory' => 12, 'costParallel' => 2]));
// SCryptModified tested are in provider-specific tests below
@@ -149,10 +149,10 @@ class AuthTest extends TestCase
$saltSeparator = 'Bw==';
$signerKey = 'XyEKE9RcTDeLEsL/RjwPDBv/RqDl8fb3gpYEOQaPihbxf1ZAtSOHCjuAAa7Q3oHpCYhXSN9tizHgVOwn6krflQ==';
$options = [ 'salt' => $salt, 'salt_separator' => $saltSeparator, 'signer_key' => $signerKey ];
$generatedHash = Auth::passwordHash($plain, 'scrypt_mod', $options);
$this->assertEquals(true, Auth::passwordVerify($plain, $generatedHash, 'scrypt_mod', $options));
$this->assertEquals(true, Auth::passwordVerify($plain, $hash, 'scrypt_mod', $options));
$options = [ 'salt' => $salt, 'saltSeparator' => $saltSeparator, 'signerKey' => $signerKey ];
$generatedHash = Auth::passwordHash($plain, 'scryptMod', $options);
$this->assertEquals(true, Auth::passwordVerify($plain, $generatedHash, 'scryptMod', $options));
$this->assertEquals(true, Auth::passwordVerify($plain, $hash, 'scryptMod', $options));
}
public function testUnknownAlgo()