8000 Deprecate Argon2i encoder used in make:user · symfony/maker-bundle@dee904b · GitHub
[go: up one dir, main page]

Skip to content

Commit dee904b

Browse files
nicolas-grekasweaverryan
authored andcommitted
Deprecate Argon2i encoder used in make:user
1 parent fe60f93 commit dee904b

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/Maker/MakeUser.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Symfony\Component\Console\Input\InputInterface;
3333
use Symfony\Component\Console\Input\InputOption;
3434
use Symfony\Component\Security\Core\Encoder\Argon2iPasswordEncoder;
35+
use Symfony\Component\Security\Core\Encoder\NativePasswordEncoder;
3536
use Symfony\Component\Yaml\Yaml;
3637

3738
/**
@@ -67,7 +68,7 @@ public function configureCommand(Command $command, InputConfiguration $inputConf
6768
->addOption('is-entity', null, InputOption::VALUE_NONE, 'Do you want to store user data in the database (via Doctrine)?')
6869
->addOption('identity-property-name', null, InputOption::VALUE_REQUIRED, 'Enter a property name that will be the unique "display" name for the user (e.g. <comment>email, username, uuid</comment>)')
6970
->addOption('with-password', null, InputOption::VALUE_NONE, 'Will this app be responsible for checking the password? Choose <comment>No</comment> if the password is actually checked by some other system (e.g. a single sign-on server)')
70-
->addOption('use-argon2', null, InputOption::VALUE_NONE, 'Use the Argon2i password encoder?')
71+
->addOption('use-argon2', null, InputOption::VALUE_NONE, 'Use the Argon2i password encoder? (deprecated)')
7172
->setHelp(file_get_contents(__DIR__.'/../Resources/help/MakeUser.txt'))
7273
;
7374

@@ -107,12 +108,12 @@ class_exists(DoctrineBundle::class)
107108
$input->setOption('with-password', $userWillHavePassword);
108109

109110
$useArgon2Encoder = false;
110-
if ($userWillHavePassword && Argon2iPasswordEncoder::isSupported()) {
111+
if ($userWillHavePassword && !class_exists(NativePasswordEncoder::class) && Argon2iPasswordEncoder::isSupported()) {
111112
$io->writeln('The newer <comment>Argon2i</comment> password hasher requires PHP 7.2, libsodium or paragonie/sodium_compat. Your system DOES support this algorithm.');
112113
$io->writeln('You should use <comment>Argon2i</comment> unless your production system will not support it.');
113114
$useArgon2Encoder = $io->confirm('Use <comment>Argon2i</comment> as your password hasher (bcrypt will be used otherwise)?');
115+
$input->setOption('use-argon2', $useArgon2Encoder);
114116
}
115-
$input->setOption('use-argon2', $useArgon2Encoder);
116117
}
117118

118119
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator)
@@ -122,7 +123,10 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
122123
$input->getOption('identity-property-name'),
123124
$input->getOption('with-password')
124125
);
125-
$userClassConfiguration->useArgon2($input->getOption('use-argon2'));
126+
if ($input->getOption('use-argon2')) {
127+
@trigger_error('The "--use-argon2" option is deprecated since MakerBundle 1.12.', E_USER_DEPRECATED);
128+
$userClassConfiguration->useArgon2(true);
129+
}
126130

127131
$userClassNameDetails = $generator->createClassNameDetails(
128132
$input->getArgument('name'),

src/Security/SecurityConfigUpdater.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\MakerBundle\Security;
1313

1414
use Symfony\Bundle\MakerBundle\Util\YamlSourceManipulator;
15+
use Symfony\Component\Security\Core\Encoder\NativePasswordEncoder;
1516

1617
/**
1718
* @internal
@@ -137,7 +138,7 @@ private function updateEncoders(UserClassConfiguration $userConfig, string $user
137138
}
138139

139140
$newData['security']['encoders'][$userClass] = [
140-
'algorithm' => $userConfig->shouldUseArgon2() ? 'argon2i' : 'bcrypt',
141+
'algorithm' => $userConfig->shouldUseArgon2() ? 'argon2i' : (class_exists(NativePasswordEncoder::class) ? 'auto' : 'bcrypt'),
141142
];
142143
$newData['security']['encoders']['_'] = $this->manipulator->createEmptyLine();
143144

src/Security/UserClassConfiguration.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class UserClassConfiguration
2424

2525
private $hasPassword;
2626

27-
private $useArgon2 = true;
27+
private $useArgon2 = false;
2828

2929
private $userProviderClass;
3030

@@ -50,11 +50,17 @@ public function hasPassword(): bool
5050
return $this->hasPassword;
5151
}
5252

53+
/**
54+
* @deprecated since MakerBundle 1.12
55+
*/
5356
public function useArgon2(bool $shouldUse)
5457
{
5558
$this->useArgon2 = $shouldUse;
5659
}
5760

61+
/**
62+
* @deprecated since MakerBundle 1.12
63+
*/
5864
public function shouldUseArgon2(): bool
5965
{
6066
return $this->useArgon2;

0 commit comments

Comments
 (0)
0