8000 minor #21620 [Security] Saltless Encoder Interface (zanbaldwin) · symfony/symfony@250d56b · GitHub
[go: up one dir, main page]

Skip to content

Commit 250d56b

Browse files
committed
minor #21620 [Security] Saltless Encoder Interface (zanbaldwin)
This PR was merged into the 3.4 branch. Discussion ---------- [Security] Saltless Encoder Interface | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | A new interface for encoders that do not require a user-generated salt (generate their own built-in) as suggested by @stof ([comment](https://github.com/symfony/symfony/pull/21604/files#r101225470)), this will become useful as more password encoders are added in the future (such as #21604). Commits ------- 7c4aa0b Saltless Encoder Interface
2 parents 3c262ba + 7c4aa0b commit 250d56b

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
use Symfony\Component\Console\Output\OutputInterface;
2020
use Symfony\Component\Console\Question\Question;
2121
use Symfony\Component\Console\Style\SymfonyStyle;
22-
use Symfony\Component\Security\Core\Encoder\BCryptPasswordEncoder;
2322
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
23+
use Symfony\Component\Security\Core\Encoder\SelfSaltingEncoderInterface;
2424
use Symfony\Component\Security\Core\User\User;
2525

2626
/**
@@ -117,9 +117,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
117117

118118
$encoderFactory = $this->encoderFactory ?: $this->getContainer()->get('security.encoder_factory');
119119
$encoder = $encoderFactory->getEncoder($userClass);
120-
$bcryptWithoutEmptySalt = !$emptySalt && $encoder instanceof BCryptPasswordEncoder;
120+
$saltlessWithoutEmptySalt = !$emptySalt && $encoder instanceof SelfSaltingEncoderInterface;
121121

122-
if ($bcryptWithoutEmptySalt) {
122+
if ($saltlessWithoutEmptySalt) {
123123
$emptySalt = true;
124124
}
125125

@@ -161,8 +161,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
161161

162162
if (!$emptySalt) {
163163
$errorIo->note(sprintf('Make sure that your salt storage field fits the salt length: %s chars', strlen($salt)));
164-
} elseif ($bcryptWithoutEmptySalt) {
165-
$errorIo->note('Bcrypt encoder used: the encoder generated its own built-in salt.');
< 8000 /code>
164+
} elseif ($saltlessWithoutEmptySalt) {
165+
$errorIo->note('Self-salting encoder used: the encoder generated its own built-in salt.');
166166
}
167167

168168
$errorIo->success('Password encoding succeeded');

src/Symfony/Bundle/SecurityBundle/Tests/Functional/UserPasswordEncoderCommandTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,11 @@ public function testEncodePasswordEmptySaltOutput()
120120

121121
public function testEncodePasswordBcryptOutput()
122122
{
123-
$this->passwordEncoderCommandTester->execute(
124-
array(
125-
'command' => 'security:encode-password',
126-
'password' => 'p@ssw0rd',
127-
'user-class' => 'Custom\Class\Bcrypt\User',
128-
)
129-
);
123+
$this->passwordEncoderCommandTester->execute(array(
124+
'command' => 'security:encode-password',
125+
'password' => 'p@ssw0rd',
126+
'user-class' => 'Custom\Class\Bcrypt\User',
127+
), array('interactive' => false));
130128

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

src/Symfony/Component/Security/Core/Encoder/BCryptPasswordEncoder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @author Elnur Abdurrakhimov <elnur@elnur.pro>
1818
* @author Terje Bråten <terje@braten.be>
1919
*/
20-
class BCryptPasswordEncoder extends BasePasswordEncoder
20+
class BCryptPasswordEncoder extends BasePasswordEncoder implements SelfSaltingEncoderInterface
2121
{
2222
const MAX_PASSWORD_LENGTH = 72;
2323

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Core\Encoder;
13+
14+
/**
15+
* SelfSaltingEncoderInterface is a marker interface for encoders that do not
16+
* require a user-generated salt.
17+
*
18+
* @author Zan Baldwin <hello@zanbaldwin.com>
19+
*/
20+
interface SelfSaltingEncoderInterface
21+
{
22+
}

0 commit comments

Comments
 (0)
0