Last active
February 4, 2016 13:03
-
-
Save fesor/e5f8f36a7c4e83ff3fdb to your computer and use it in GitHub Desktop.
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
<?php | |
class SecureCodeGenerator { | |
private $secureRandom; | |
public function __construct(SecureRandomInterface $secureRandom) { | |
this->secureRandom = $secureRandom; | |
} | |
public function generate() { | |
$confirmationCode = $this | |
->secureRandom | |
->nextBytes(4); | |
return md5($confirmationCode); | |
} | |
} | |
class AccountManager | |
{ | |
private $secureCodeGenerator; | |
public function __construct( | |
SecureCodeGenerator $secureCodeGenerator | |
) { | |
$this->secureCodeGenerator = $secureCodeGenerator; | |
} | |
public function createAccount(Account $account) | |
{ | |
$account->setConfirmationCode( | |
$this->secureCodeGenerator->generate() | |
); | |
} | |
} |
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
<?php | |
class AccountManager | |
{ | |
private $entityManager; | |
private $secureRandom; | |
public function __construct( | |
SecureRandomInterface $secureRandom | |
) { | |
$this->secureRandom = $secureRandom; | |
} | |
public function createAccount(Account $account) | |
{ | |
$confirmationCode = $this | |
->secureRandom | |
->nextBytes(4); | |
$account | |
->setConfirmationCode(md5($confirmationCode)); | |
} | |
} |
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
<?php | |
class AccountManager | |
{ | |
private $entityManager; | |
private $secureRandom; | |
public function __construct( | |
EntityManger $entityManager, | |
SecureRandomInterface $secureRandom | |
) { | |
$this->entityManager = $entityManager; | |
$this->secureRandom = $secureRandom; | |
} | |
public function createAccount(Account $account) | |
{ | |
$confirmationCode = $this | |
->secureRandom | |
->nextBytes(4); | |
$account | |
->setConfirmationCode(md5($confirmationCode)); | |
$this->entityManager->persist($account); | |
$this->entityManager->flush(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment