-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathUserIdentity.php
More file actions
69 lines (60 loc) · 1.6 KB
/
UserIdentity.php
File metadata and controls
69 lines (60 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter Shield.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\Shield\Entities;
use CodeIgniter\Entity\Entity;
use CodeIgniter\I18n\Time;
use CodeIgniter\Shield\Authentication\Passwords;
/**
* Class UserIdentity
*
* Represents a single set of user identity credentials.
* For the base Shield system, this would be one of the following:
* - password
* - reset hash
* - access token
*
* This can also be used to store credentials for social logins,
* OAUTH or JWT tokens, etc. A user can have multiple of each,
* though a Authenticator may want to enforce only one exists for that
* user, like a password.
*
* @property string|Time|null $last_used_at
* @property string|null $secret
* @property string|null $secret2
*/
class UserIdentity extends Entity
{
/**
* @var array<string, string>
*/
protected $casts = [
'id' => '?integer',
'force_reset' => 'int-bool',
];
/**
* @var list<string>
*/
protected $dates = [
'expires',
'last_used_at',
];
/**
* Uses password-strength hashing to hash
* a given value for the 'secret'.
*/
public function hashSecret(string $value): UserIdentity
{
/** @var Passwords $passwords */
$passwords = service('passwords');
$this->attributes['secret'] = $passwords->hash($value);
return $this;
}
}