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

nette / security / 22835249014

09 Mar 2026 01:53AM UTC coverage: 91.812%. Remained the same
22835249014

push

github

dg
User: deprecated magic properties (BC break)

527 of 574 relevant lines covered (91.81%)

0.92 hits per line

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

92.31
/src/Security/Passwords.php
1
<?php declare(strict_types=1);
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
namespace Nette\Security;
9

10
use Nette;
11

12

13
/**
14
 * Password hashing and verification.
15
 */
16
class Passwords
17
{
18
        /**
19
         * Configures the hashing algorithm and its options.
20
         */
21
        public function __construct(
1✔
22
                private readonly string $algo = PASSWORD_DEFAULT,
23
                /** @var array<string, mixed>  algorithm-specific options, see https://php.net/manual/en/password.constants.php */
24
                private readonly array $options = [],
25
        ) {
26
        }
1✔
27

28

29
        /**
30
         * Computes a password hash containing the algorithm ID, settings, salt, and the hash itself.
31
         */
32
        public function hash(
1✔
33
                #[\SensitiveParameter]
34
                string $password,
35
        ): string
36
        {
37
                if ($password === '') {
1✔
38
                        throw new Nette\InvalidArgumentException('Password can not be empty.');
1✔
39
                }
40

41
                $hash = @password_hash($password, $this->algo, $this->options); // @ is escalated to exception
1✔
42
                if (!$hash) {
1✔
43
                        throw new Nette\InvalidStateException('Computed hash is invalid. ' . (error_get_last()['message'] ?? ''));
×
44
                }
45

46
                return $hash;
1✔
47
        }
48

49

50
        /**
51
         * Checks whether the password matches the given hash.
52
         */
53
        public function verify(
1✔
54
                #[\SensitiveParameter]
55
                string $password,
56
                string $hash,
57
        ): bool
58
        {
59
                return password_verify($password, $hash);
1✔
60
        }
61

62

63
        /**
64
         * Checks whether the hash needs to be rehashed with the current algorithm and options.
65
         */
66
        public function needsRehash(string $hash): bool
1✔
67
        {
68
                return password_needs_rehash($hash, $this->algo, $this->options);
1✔
69
        }
70
}
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