8000 [SecurityBundle] UserPasswordEncoderCommand: Improve & simplify the command usage by ogizanagi · Pull Request #14032 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[SecurityBundle] UserPasswordEncoderCommand: Improve & simplify the command usage #14032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[SecurityBundle] UserPasswordEncoderCommand: Let the bcrypt encoder g…
…enerate its built-in salt
  • Loading branch information
ogizanagi committed Apr 6, 2015
commit 289de2faf86b331f02319f2bd59af2a84570c7cd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;

/**
* Encode a user's password.
Expand Down Expand Up @@ -87,8 +88,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->writeIntroduction($output);

$password = $input->getArgument('password');
$emptySalt = $input->getOption('empty-salt');
$userClass = $input->getArgument('user-class');
$encoder = $this->getContainer()->get('security.encoder_factory')->getEncoder($userClass);
$emptySalt = $input->getOption('empty-salt') || $encoder instanceof BCryptPasswordEncoder;

$helper = $this->getHelper('question');

Expand All @@ -112,7 +114,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$salt = $this->generateSalt();
}

$encoder = $this->getContainer()->get('security.encoder_factory')->getEncoder($userClass);
$encodedPassword = $encoder->encodePassword($password, $salt);

$this->writeResult($output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ public function testEncodePasswordEmptySaltOutput()
$this->assertNotContains('| Generated salt |', $this->passwordEncoderCommandTester->getDisplay());
}

public function testEncodePasswordBcryptOutput()
{
$this->passwordEncoderCommandTester->execute(
array(
'command' => 'security:encode-password',
'password' => 'p@ssw0rd',
'user-class' => 'Custom\Class\Bcrypt\User',
)
);

$this->assertNotContains('| Generated salt |', $this->passwordEncoderCommandTester->getDisplay());
}

public function testEncodePasswordNoConfigForGivenUserClass()
{
$this->setExpectedException('\RuntimeException', 'No encoder has been configured for account "Foo\Bar\User".');
Expand Down
0