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

nette / security / 22292290616

23 Feb 2026 03:52AM UTC coverage: 92.466%. Remained the same
22292290616

push

github

dg
added CLAUDE.md

540 of 584 relevant lines covered (92.47%)

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
use const PASSWORD_DEFAULT;
12

13

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

29

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

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

47
                return $hash;
1✔
48
        }
49

50

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

63

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