Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 3e0c012

Browse files
Marc FeiningerMarc Feininger
authored andcommitted
merged smottt/FOSAdvancedEncoderBundle for adding bcrypt
Conflicts: DependencyInjection/Configuration.php DependencyInjection/FOSAdvancedEncoderExtension.php Tests/DependencyInjection/FOSAdvancedEncoderExtensionTest.php
2 parents 37cc948 + 3db4b7f commit 3e0c012

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function getConfigTreeBuilder()
5151
->booleanNode('ignore_case')->defaultFalse()->end()
5252
->booleanNode('encode_as_base64')->defaultTrue()->end()
5353
->scalarNode('iterations')->defaultValue(5000)->end()
54+
->scalarNode('cost')->defaultValue(13)->end()
5455
->scalarNode('hash_algorithm')->defaultValue('sha512')->end()
5556
->scalarNode('key_length')->defaultValue(40)->end()
5657
->scalarNode('id')->end()

DependencyInjection/FOSAdvancedEncoderExtension.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ private function createEncoder($config)
5353
);
5454
}
5555

56+
// bcrypt encoder
57+
if ('bcrypt' === $config['algorithm']) {
58+
$arguments = array($config['cost']);
59+
60+
return array(
61+
'class' => new Parameter('security.encoder.bcrypt.class'),
62+
'arguments' => $arguments,
63+
);
64+
}
65+
5666
// pbkdf2 encoder
5767
if ('pbkdf2' === $config['algorithm']) {
5868
$arguments = array(
@@ -64,10 +74,10 @@ private function createEncoder($config)
6474

6575
return array(
6676
'class' => new Parameter('security.encoder.pbkdf2.class'),
67-
'arguments' => $arguments
77+
'arguments' => $arguments,
6878
);
6979
}
70-
80+
7181
// message digest encoder
7282
$arguments = array(
7383
$config['algorithm'],

Tests/DependencyInjection/FOSAdvancedEncoderExtensionTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,17 @@ public function testLoadFullConfiguration()
4343
'custom' => array(
4444
'id' => 'acme_demo.encoder',
4545
),
46+
'bcrypt' => array(
47+
'algorithm' => 'bcrypt',
48+
'cost' => 16,
49+
),
4650
'pbkdf2' => array(
4751
'algorithm' => 'pbkdf2',
4852
'hash_algorithm' => 'sha512',
4953
'encode_as_base64' => false,
5054
'iterations' => 2,
5155
'key_length' => 40,
52-
)
56+
),
5357
),
5458
);
5559
$loader->load(array($config), $container);
@@ -72,10 +76,14 @@ public function testLoadFullConfiguration()
7276
'arguments' => array(false),
7377
),
7478
'custom' => new Reference('acme_demo.encoder'),
79+
'bcrypt' => array(
80+
'class' => new Parameter('security.encoder.bcrypt.class'),
81+
'arguments' => array(16),
82+
),
7583
'pbkdf2' => array(
7684
'class' => new Parameter('security.encoder.pbkdf2.class'),
7785
'arguments' => array('sha512', false, 2, 40),
78-
)
86+
),
7987
)
8088
)
8189
);

0 commit comments

Comments
 (0)