@@ -53,6 +53,11 @@ trait TOTP
53
53
*/
54
54
private $ graceperiod = 10 ;
55
55
56
+ /**
57
+ * @var bool token after password
58
+ */
59
+ private $ passwordFirst = false ;
60
+
56
61
/**
57
62
* @var string method accepting username and returning a simplexml user object
58
63
*/
@@ -149,8 +154,14 @@ public function authenticate($username, $password)
149
154
if ($ userObject != null && !empty ($ userObject ->otp_seed )) {
150
155
if (strlen ($ password ) > $ this ->otpLength ) {
151
156
// split otp token code and userpassword
152
- $ code = substr ($ password , 0 , $ this ->otpLength );
153
- $ userPassword = substr ($ password , $ this ->otpLength );
157
+ $ pwStart = $ this ->otpLength ;
158
+ $ otpStart = 0 ;
159
+ if ($ this ->passwordFirst ) {
160
+ $ otpStart = strlen ($ password ) - $ this ->otpLength ;
161
+ $ pwStart = 0 ;
162
+ }
163
+ $ userPassword = substr ($ password , $ pwStart , strlen ($ password ) - $ this ->otpLength );
164
+ $ code = substr ($ password , $ otpStart , $ this ->otpLength );
154
165
$ otp_seed = \Base32 \Base32::decode ($ userObject ->otp_seed );
155
166
if ($ this ->authTOTP ($ otp_seed , $ code )) {
156
167
// token valid, do parents auth
@@ -176,6 +187,9 @@ public function setTOTPProperties($config)
176
187
if (!empty ($ config ['graceperiod ' ])) {
177
188
$ this ->graceperiod = $ config ['graceperiod ' ];
178
189
}
190
+ if (array_key_exists ('passwordFirst ' , $ config ) && !empty ($ config ['passwordFirst ' ])) {
191
+ $ this ->passwordFirst = true ;
192
+ }
179
193
}
180
194
181
195
/**
@@ -226,6 +240,13 @@ private function getTOTPConfigurationOptions()
226
240
return array ();
227
241
}
228
242
};
243
+ $ fields ["passwordFirst " ] = array ();
244
+ $ fields ["passwordFirst " ]["name " ] = gettext ("Reverse token order " );
245
+ $ fields ["passwordFirst " ]["help " ] = gettext ("Require the password in front of the token instead of behind it. " );
246
+ $ fields ["passwordFirst " ]["type " ] = "checkbox " ;
247
+ $ fields ["passwordFirst " ]["validate " ] = function ($ value ) {
248
+ return array ();
249
+ };
229
250
230
251
return $ fields ;
231
252
}
0 commit comments