File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -188,6 +188,12 @@ component singleton accessors="true" {
188188 numeric time = variables .instant .no w ().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 }
You can’t perform that action at this time.
0 commit comments