Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e44dac1
Update comments for groups in AuthGroups.php
iamsyh Nov 3, 2022
f112e1d
Update src/Config/AuthGroups.php
iamsyh Nov 4, 2022
ff3a495
Merge branch 'codeigniter4:develop' into patch-1
iamsyh Nov 5, 2022
96ed853
docs: add annotation for psalm
kenjis Nov 10, 2022
fcb6d3c
docs: fix code block languages
datamweb Nov 12, 2022
fd0d446
docs: add code block language for install command
datamweb Nov 12, 2022
2aadb30
docs: update doc comments on hashing algorithm
kenjis Nov 15, 2022
5483eca
docs: update values for ARGON2I/ARGON2ID Algorithm options
kenjis Nov 15, 2022
0f79712
style: break long line
kenjis Nov 15, 2022
af66c7b
fix: $minimumPasswordLength is not in characters but in bytes
kenjis Nov 15, 2022
f8b19b5
docs: fix property notation
kenjis Nov 15, 2022
94a277a
Merge pull request #523 from datamweb/doc-fix-for-website
kenjis Nov 15, 2022
9f7171f
Merge pull request #526 from kenjis/fix-Config-Auth-password-hashing
kenjis Nov 15, 2022
3aeafc8
Merge pull request #528 from kenjis/fix-docs-concepts.md
kenjis Nov 15, 2022
df01dd7
fix: add UTF-8 to mb_strlen()
kenjis Nov 15, 2022
0216f6f
Update src/Config/AuthGroups.php
iamsyh Nov 16, 2022
16c8807
Merge branch 'codeigniter4:develop' into patch-1
iamsyh Nov 16, 2022
4475332
Update AuthGroups.php
iamsyh Nov 16, 2022
b3b6c23
docs: use @phpstan-consistent-constructor instead of paslm's
kenjis Nov 16, 2022
c6c2abe
Merge pull request #527 from kenjis/fix-minimumPasswordLength
datamweb Nov 16, 2022
fb4f33d
Update src/Config/AuthGroups.php
paulbalandan Nov 18, 2022
bfbbd03
Merge pull request #507 from iamsyh/patch-1
MGatner Nov 18, 2022
c75b41d
Merge pull request #518 from kenjis/docs-remove-psalm-issues
kenjis Nov 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ Usage of Shield requires the following:
### Installation

Installation is done through Composer.

> composer require codeigniter4/shield
```console
composer require codeigniter4/shield
```

See the [docs](docs/index.md) for more specific instructions on installation and usage recommendations.

Expand Down
10 changes: 5 additions & 5 deletions docs/concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ on the standard Config class if nothing is found in the database.
## User Providers

You can use your own models to handle user persistence. Shield calls this the "User Provider" class. A default model
is provided for you at `CodeIgniter\Shield\Models\UserModel`. You can change this in the `Config\Auth->userProvider` setting.
is provided for you at `CodeIgniter\Shield\Models\UserModel`. You can change this in the `Config\Auth::$userProvider` setting.
The only requirement is that your new class MUST extend the provided `UserModel`.

```php
Expand Down Expand Up @@ -57,13 +57,13 @@ systems that are appropriate for your application. The following Validators are
like ensuring it contained a symbol, a number, etc. According to the current
[NIST recommendations](https://pages.nist.gov/800-63-3/sp800-63b.html) this only enforces a
minimum length on the password. You can define the minimum length in
`Config\Auth->public $minimumPasswordLength;` This is enabled by default. The default minimum
`Config\Auth::$minimumPasswordLength` This is enabled by default. The default minimum
value is `8`.
- **NothingPersonalValidator** will compare the password against any fields that have been specified
in `Config\Auth->personalFields`, like first or last names, etc. Additionally, it compares it
in `Config\Auth::$personalFields`, like first or last names, etc. Additionally, it compares it
against a few simple variations of the username. If the given password too closely matches
any of the personal information, it will be rejected. The similarity value is defined in
`Config\Auth->maxSimilarity`. The default value is 50, but see the docblock in the config
`Config\Auth::$maxSimilarity`. The default value is 50, but see the docblock in the config
file for more details. This is enabled by default.
- **DictionaryValidator** will compare the password against a provided file with about 600,000
frequently used passwords that have been seen in various data dumps over the years. If the
Expand All @@ -76,7 +76,7 @@ systems that are appropriate for your application. The following Validators are
find acceptable. You should use either this validator or the `DictionaryValidator`, not both.
This is disabled by default.

You can choose which validators are used in `Config\Auth->passwordValidators`:
You can choose which validators are used in `Config\Auth::$passwordValidators`:

```php
public $passwordValidators = [
Expand Down
22 changes: 11 additions & 11 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ These instructions assume that you have already [installed the CodeIgniter 4 app
Installation is done through [Composer](https://getcomposer.org). The example assumes you have it installed globally.
If you have it installed as a phar, or otherwise you will need to adjust the way you call composer itself.

```
> composer require codeigniter4/shield
```console
composer require codeigniter4/shield
```

### Troubleshooting
Expand All @@ -35,29 +35,29 @@ If you have it installed as a phar, or otherwise you will need to adjust the way

If you get the following error:

```
Could not find a version of package codeigniter4/shield matching your minimum-stability (stable).
Require it with an explicit version constraint allowing its desired stability.
```console
Could not find a version of package codeigniter4/shield matching your minimum-stability (stable).
Require it with an explicit version constraint allowing its desired stability.
```

1. Add the following to change your [minimum-stability](https://getcomposer.org/doc/articles/versions.md#minimum-stability) in your project `composer.json`:

```json
"minimum-stability": "dev",
"prefer-stable": true,
"minimum-stability": "dev",
"prefer-stable": true,
```

2. Or specify an explicit version:

```console
> composer require codeigniter4/shield:dev-develop
composer require codeigniter4/shield:dev-develop
```

The above specifies `develop` branch.
See https://getcomposer.org/doc/articles/versions.md#branches

```console
> composer require codeigniter4/shield:^1.0.0-beta
composer require codeigniter4/shield:^1.0.0-beta
```

The above specifies `v1.0.0-beta` or later and before `v2.0.0`.
Expand All @@ -70,7 +70,7 @@ If you get the following error:
1. Run the following command. This command handles steps 1-5 of *Manual Setup* and runs the migrations.

```console
> php spark shield:setup
php spark shield:setup
```

### Manual Setup
Expand Down Expand Up @@ -120,7 +120,7 @@ your project.
5. **Migration** Run the migrations.

```console
> php spark migrate --all
php spark migrate --all
```

#### Note: migration error
Expand Down
1 change: 1 addition & 0 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function getProvider(): UserModel
return $this->userProvider;
}

/** @var \CodeIgniter\Shield\Config\Auth $config */
$config = config('Auth');

if (! property_exists($config, 'userProvider')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Authentication/Passwords/CompositionValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function check(string $password, ?User $user = null): Result
throw AuthenticationException::forUnsetPasswordLength();
}

$passed = strlen($password) >= $this->config->minimumPasswordLength;
$passed = mb_strlen($password, 'UTF-8') >= $this->config->minimumPasswordLength;

if (! $passed) {
return new Result([
Expand Down
23 changes: 8 additions & 15 deletions src/Config/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,41 +278,34 @@ class Auth extends BaseConfig

/**
* --------------------------------------------------------------------
* Encryption Algorithm to use
* Hashing Algorithm to use
* --------------------------------------------------------------------
* Valid values are
* - PASSWORD_DEFAULT (default)
* - PASSWORD_BCRYPT
* - PASSWORD_ARGON2I - As of PHP 7.2 only if compiled with support for it
* - PASSWORD_ARGON2ID - As of PHP 7.3 only if compiled with support for it
*
* If you choose to use any ARGON algorithm, then you might want to
* uncomment the "ARGON2i/D Algorithm" options to suit your needs
*/
public string $hashAlgorithm = PASSWORD_DEFAULT;

/**
* --------------------------------------------------------------------
* ARGON2i/D Algorithm options
* ARGON2I/ARGON2ID Algorithm options
* --------------------------------------------------------------------
* The ARGON2I method of encryption allows you to define the "memory_cost",
* The ARGON2I method of hashing allows you to define the "memory_cost",
* the "time_cost" and the number of "threads", whenever a password hash is
* created.
* This defaults to a value of 10 which is an acceptable number.
* However, depending on the security needs of your application
* and the power of your hardware, you might want to increase the
* cost. This makes the hashing process takes longer.
*/
public int $hashMemoryCost = 2048; // PASSWORD_ARGON2_DEFAULT_MEMORY_COST;
public int $hashMemoryCost = 65536; // PASSWORD_ARGON2_DEFAULT_MEMORY_COST;

public int $hashTimeCost = 4; // PASSWORD_ARGON2_DEFAULT_TIME_COST;
public int $hashThreads = 4; // PASSWORD_ARGON2_DEFAULT_THREADS;
public int $hashTimeCost = 4; // PASSWORD_ARGON2_DEFAULT_TIME_COST;
public int $hashThreads = 1; // PASSWORD_ARGON2_DEFAULT_THREADS;

/**
* --------------------------------------------------------------------
* Password Hashing Cost
* BCRYPT Algorithm options
* --------------------------------------------------------------------
* The BCRYPT method of encryption allows you to define the "cost"
* The BCRYPT method of hashing allows you to define the "cost"
* or number of iterations made, whenever a password hash is created.
* This defaults to a value of 10 which is an acceptable number.
* However, depending on the security needs of your application
Expand Down
13 changes: 9 additions & 4 deletions src/Config/AuthGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ class AuthGroups extends BaseConfig
* --------------------------------------------------------------------
* Groups
* --------------------------------------------------------------------
* The available authentication systems, listed
* with alias and class name. These can be referenced
* by alias in the auth helper:
* auth('api')->attempt($credentials);
* An associative array of the available groups in the system, where the keys are
* the group names and the values are arrays of the group info.
*
* Whatever value you assign as the key will be used to refer to the group when using functions such as:
* $user->addGroup('superadmin');
*
* @var array<string, array<string, string>>
*
* @see https://github.com/codeigniter4/shield/blob/develop/docs/quickstart.md#change-available-groups for more info
*/
public array $groups = [
'superadmin' => [
Expand Down
2 changes: 2 additions & 0 deletions src/Entities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

/**
* @property string|null $email
* @property int|string|null $id
* @property UserIdentity[]|null $identities
* @property Time|null $last_active
* @property string|null $password
* @property string|null $password_hash
* @property string|null $username
*/
class User extends Entity
{
Expand Down
3 changes: 3 additions & 0 deletions src/Models/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
use CodeIgniter\Shield\Exceptions\ValidationException;
use Faker\Generator;

/**
* @phpstan-consistent-constructor
*/
class UserModel extends Model
{
use CheckQueryReturnTrait;
Expand Down
18 changes: 17 additions & 1 deletion tests/Unit/CompositionValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,23 @@ public function testCheckFalse(): void
$result = $this->validator->check($password);

$this->assertFalse($result->isOK());
$this->assertSame(lang('Auth.errorPasswordLength', [$this->config->minimumPasswordLength]), $result->reason());
$this->assertSame(
lang('Auth.errorPasswordLength', [$this->config->minimumPasswordLength]),
$result->reason()
);
}

public function testCheckFalseMultibyte(): void
{
$password = '🍣😀';

$result = $this->validator->check($password);

$this->assertFalse($result->isOK());
$this->assertSame(
lang('Auth.errorPasswordLength', [$this->config->minimumPasswordLength]),
$result->reason()
);
}

public function testCheckTrue(): void
Expand Down
2 changes: 2 additions & 0 deletions tests/_support/Config/Registrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Registrar
* DB config array for testing purposes.
*
* @var array
*
* @psalm-suppress RedundantCondition
*/
protected static $dbConfig = [
'MySQLi' => [
Expand Down