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

nette / security / 21812889120

09 Feb 2026 04:55AM UTC coverage: 92.414% (-0.5%) from 92.919%
21812889120

push

github

dg
added CLAUDE.md

536 of 580 relevant lines covered (92.41%)

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
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
declare(strict_types=1);
9

10
namespace Nette\Security;
11

12
use Nette;
13
use const PASSWORD_DEFAULT;
14

15

16
/**
17
 * Password Hashing.
18
 */
19
class Passwords
20
{
21
        /**
22
         * Chooses which secure algorithm is used for hashing and how to configure it.
23
         */
24
        public function __construct(
1✔
25
                private readonly string $algo = PASSWORD_DEFAULT,
26
                /** @var array<string, mixed>  algorithm-specific options, see https://php.net/manual/en/password.constants.php */
27
                private readonly array $options = [],
28
        ) {
29
        }
1✔
30

31

32
        /**
33
         * Computes password´s hash. The result contains the algorithm ID and its settings, cryptographical salt and the hash itself.
34
         */
35
        public function hash(
1✔
36
                #[\SensitiveParameter]
37
                string $password,
38
        ): string
39
        {
40
                if ($password === '') {
1✔
41
                        throw new Nette\InvalidArgumentException('Password can not be empty.');
1✔
42
                }
43

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

49
                return $hash;
1✔
50
        }
51

52

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

65

66
        /**
67
         * Finds out if the hash matches the options given in constructor.
68
         */
69
        public function needsRehash(string $hash): bool
1✔
70
        {
71
                return password_needs_rehash($hash, $this->algo, $this->options);
1✔
72
        }
73
}
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