This repository has been archived by the owner on Sep 23, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced Password PseudoRandomBytesGenerator.php
- Loading branch information
1 parent
d752fad
commit e32f29b
Showing
5 changed files
with
74 additions
and
1 deletion.
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
28 changes: 28 additions & 0 deletions
28
src/Knp/Rad/User/DependencyInjection/Compiler/PasswordGenerator.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,28 @@ | ||
<?php | ||
|
||
namespace Knp\Rad\User\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Exception\OutOfBoundsException; | ||
|
||
class PasswordGenerator implements CompilerPassInterface | ||
{ | ||
const GENERATOR_INDEX = 0; | ||
|
||
public function process(ContainerBuilder $container) | ||
{ | ||
if ( ! extension_loaded('openssl')) { | ||
return; | ||
} | ||
|
||
$listener = $container->findDefinition('knp_rad_user.event_listener.persistence.password_generation_listener'); | ||
|
||
try { | ||
$generator = $listener->getArgument(self::GENERATOR_INDEX); | ||
} catch (OutOfBoundsException $e) { | ||
$sslGenerator = $container->findDefinition('knp_rad_user.password.generator.pseudo_random_bytes_generator'); | ||
$listener->setArguments([$sslGenerator]); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Knp/Rad/User/Password/Generator/PseudoRandomBytesGenerator.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,26 @@ | ||
<?php | ||
|
||
namespace Knp\Rad\User\Password\Generator; | ||
|
||
use Knp\Rad\User\Password\Generator; | ||
|
||
class PseudoRandomBytesGenerator implements Generator | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private $length; | ||
|
||
/** | ||
* @param int $length | ||
*/ | ||
public function __construct($length) | ||
{ | ||
$this->length = $length; | ||
} | ||
|
||
public function generate() | ||
{ | ||
return openssl_random_pseudo_bytes($this->length); | ||
} | ||
} |
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