Skip to content

Commit 342d355

Browse files
wpdebruinelpete
andauthored
fix: fix false positive for empty code
* fix false positive for empty code * Update TOTP.cfc Co-authored-by: Eric Peterson <eric@elpete.com>
1 parent 5fff859 commit 342d355

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

models/TOTP.cfc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,12 @@ component singleton accessors="true" {
188188
numeric time = variables.instant.now().getEpochSecond(),
189189
numeric timePeriod = 30
190190
) {
191+
if ( arguments.digits <= 0 ) {
192+
throw(
193+
type = "totp.InvalidDigitAmount",
194+
message = "You must generate a code with a positive amount of digits."
195+
);
196+
}
191197
var counter = floor( arguments.time / arguments.timePeriod );
192198
var hash = generateHash( arguments.secret, counter, arguments.algorithm );
193199
return getDigitsFromHash( hash, arguments.digits );
@@ -247,6 +253,10 @@ component singleton accessors="true" {
247253
required numeric counter,
248254
string algorithm = "SHA1"
249255
) {
256+
// code should have a minimal length. Empty strings should not generate exceptions but just return false
257+
if ( !arguments.code.len() ) {
258+
return false;
259+
}
250260
var hash = generateHash( arguments.secret, arguments.counter, arguments.algorithm );
251261
return getDigitsFromHash( hash, arguments.code.len() ) == arguments.code;
252262
}

0 commit comments

Comments
 (0)