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

nette / security / 20848288786

09 Jan 2026 10:01AM UTC coverage: 92.919%. Remained the same
20848288786

push

github

dg
added CLAUDE.md

538 of 579 relevant lines covered (92.92%)

0.93 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
         * @see https://php.net/manual/en/password.constants.php
24
         */
25
        public function __construct(
1✔
26
                private readonly string $algo = PASSWORD_DEFAULT,
27
                /* @var  array<string, mixed>  algorithm-specific options (e.g. 'cost' for bcrypt) */
28
                private readonly array $options = [],
29
        ) {
30
        }
1✔
31

32

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

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

50
                return $hash;
1✔
51
        }
52

53

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

66

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