-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop using `Row` when another object should be used.
- Loading branch information
Showing
51 changed files
with
1,063 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
site/app/Pulse/Passwords/Algorithms/PasswordHashingAlgorithm.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace MichalSpacekCz\Pulse\Passwords\Algorithms; | ||
|
||
readonly class PasswordHashingAlgorithm | ||
{ | ||
|
||
public function __construct( | ||
private int $id, | ||
private string $name, | ||
private string $alias, | ||
private bool $salted, | ||
private bool $stretched, | ||
) { | ||
} | ||
|
||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
|
||
public function getAlias(): string | ||
{ | ||
return $this->alias; | ||
} | ||
|
||
|
||
public function isSalted(): bool | ||
{ | ||
return $this->salted; | ||
} | ||
|
||
|
||
public function isStretched(): bool | ||
{ | ||
return $this->stretched; | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
site/app/Pulse/Passwords/Algorithms/PasswordHashingAlgorithms.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
declare(strict_types = 1); | ||
|
||
namespace MichalSpacekCz\Pulse\Passwords\Algorithms; | ||
|
||
use MichalSpacekCz\Pulse\Passwords\Rating; | ||
use Nette\Database\Explorer; | ||
|
||
readonly class PasswordHashingAlgorithms | ||
{ | ||
|
||
public function __construct( | ||
private Explorer $database, | ||
private Rating $rating, | ||
) { | ||
} | ||
|
||
|
||
/** | ||
* @return list<PasswordHashingAlgorithm> | ||
*/ | ||
public function getAlgorithms(): array | ||
{ | ||
$rows = $this->database->fetchAll('SELECT id, algo, alias, salted, stretched FROM password_algos ORDER BY algo'); | ||
$algorithms = []; | ||
foreach ($rows as $row) { | ||
$algorithms[] = new PasswordHashingAlgorithm($row->id, $row->algo, $row->alias, (bool)$row->salted, (bool)$row->stretched); | ||
} | ||
return $algorithms; | ||
} | ||
|
||
|
||
public function getAlgorithmByName(string $name): ?PasswordHashingAlgorithm | ||
{ | ||
$row = $this->database->fetch('SELECT id, algo, alias, salted, stretched FROM password_algos WHERE algo = ?', $name); | ||
if (!$row) { | ||
return null; | ||
} | ||
return new PasswordHashingAlgorithm($row->id, $row->algo, $row->alias, (bool)$row->salted, (bool)$row->stretched); | ||
} | ||
|
||
|
||
/** | ||
* @return int The id of the newly inserted algorithm | ||
*/ | ||
public function addAlgorithm(string $name, string $alias, bool $salted, bool $stretched): int | ||
{ | ||
$this->database->query('INSERT INTO password_algos', [ | ||
'algo' => $name, | ||
'alias' => $alias, | ||
'salted' => $salted, | ||
'stretched' => $stretched, | ||
]); | ||
return (int)$this->database->getInsertId(); | ||
} | ||
|
||
|
||
/** | ||
* @return array<string, string> of alias => name | ||
*/ | ||
public function getSlowHashes(): array | ||
{ | ||
return $this->database->fetchPairs( | ||
'SELECT alias, algo FROM password_algos WHERE alias IN (?) ORDER BY algo', | ||
$this->rating->getSlowHashes(), | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.