• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daycry / auth / 22527658769

28 Feb 2026 07:41PM UTC coverage: 63.267% (-3.6%) from 66.864%
22527658769

push

github

web-flow
Merge pull request #36 from daycry/development

Implement TOTP 2FA, JWT auth, device session tracking, and docs overhaul

465 of 1168 new or added lines in 52 files covered. (39.81%)

129 existing lines in 46 files now uncovered.

3064 of 4843 relevant lines covered (63.27%)

41.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

55.56
/src/Entities/UserIdentity.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of Daycry Auth.
7
 *
8
 * (c) Daycry <daycry9@proton.me>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Daycry\Auth\Entities;
15

16
use CodeIgniter\I18n\Time;
17
use Daycry\Auth\Authentication\Passwords;
18

19
/**
20
 * Class UserIdentity
21
 *
22
 * Represents a single set of user identity credentials.
23
 * For the base Shield system, this would be one of the following:
24
 *  - password
25
 *  - reset hash
26
 *  - access token
27
 *
28
 * This can also be used to store credentials for social logins,
29
 * OAUTH or JWT tokens, etc. A user can have multiple of each,
30
 * though a Authenticator may want to enforce only one exists for that
31
 * user, like a password.
32
 *
33
 * @property string|Time|null $last_used_at
34
 * @property string|null      $secret
35
 * @property string|null      $secret2
36
 */
37
class UserIdentity extends Entity
38
{
39
    private ?User $user = null;
40

41
    /**
42
     * @var array<string, string>
43
     */
44
    protected $casts = [
45
        'id'          => '?integer',
46
        'force_reset' => 'int_bool',
47
    ];
48

49
    /**
50
     * @var         list<string>
51
     * @phpstan-var list<string>
52
     * @psalm-var list<string>
53
     */
54
    protected $dates = [
55
        'expires',
56
        'last_used_at',
57
        'created_at',
58
        'updated_at',
59
        'deleted_at',
60
    ];
61

62
    /**
63
     * Uses password-strength hashing to hash
64
     * a given value for the 'secret'.
65
     */
UNCOV
66
    public function hashSecret(string $value): UserIdentity
×
67
    {
68
        /** @var Passwords $passwords */
69
        $passwords = service('passwords');
×
70

71
        $this->attributes['secret'] = $passwords->hash($value);
×
72

73
        return $this;
×
74
    }
75

76
    /**
77
     * Returns the user associated with this token.
78
     */
79
    public function user(): ?User
6✔
80
    {
81
        if ($this->user === null) {
6✔
82
            $users      = auth()->getProvider();
6✔
83
            $this->user = $users->findById($this->user_id);
6✔
84
        }
85

86
        return $this->user;
6✔
87
    }
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc