This repository was archived by the owner on May 31, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,9 @@ public function getEncoder($user)
69
69
*/
70
70
private function createEncoder (array $ config )
71
71
{
72
+ if (isset ($ config ['algorithm ' ])) {
73
+ $ config = $ this ->getEncoderConfigFromAlgorithm ($ config );
74
+ }
72
75
if (!isset ($ config ['class ' ])) {
73
76
throw new \InvalidArgumentException (sprintf ('"class" must be set in %s. ' , json_encode ($ config )));
74
77
}
@@ -80,4 +83,41 @@ private function createEncoder(array $config)
80
83
81
84
return $ reflection ->newInstanceArgs ($ config ['arguments ' ]);
82
85
}
86
+
87
+ private function getEncoderConfigFromAlgorithm ($ config )
88
+ {
89
+ switch ($ config ['algorithm ' ]) {
90
+ case 'plaintext ' :
91
+ return array (
92
+ 'class ' => PlaintextPasswordEncoder::class,
93
+ 'arguments ' => array ($ config ['ignore_case ' ]),
94
+ );
95
+
96
+ case 'pbkdf2 ' :
97
+ return array (
98
+ 'class ' => Pbkdf2PasswordEncoder::class,
99
+ 'arguments ' => array (
100
+ $ config ['hash_algorithm ' ],
101
+ $ config ['encode_as_base64 ' ],
102
+ $ config ['iterations ' ],
103
+ $ config ['key_length ' ],
104
+ ),
105
+ );
106
+
107
+ case 'bcrypt ' :
108
+ return array (
109
+ 'class ' => BCryptPasswordEncoder::class,
110
+ 'arguments ' => array ($ config ['cost ' ]),
111
+ );
112
+ }
113
+
114
+ return array (
115
+ 'class ' => MessageDigestPasswordEncoder::class,
116
+ 'arguments ' => array (
117
+ $ config ['algorithm ' ],
118
+ $ config ['encode_as_base64 ' ],
119
+ $ config ['iterations ' ],
120
+ ),
121
+ );
122
+ }
83
123
}
You can’t perform that action at this time.
0 commit comments