File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -198,20 +198,23 @@ const internal2fa = {
198198 return false ;
199199 }
200200
201- // Try TOTP code first
202- const result = await verify ( {
203- token,
204- secret,
205- } ) ;
206-
207- if ( result . valid ) {
208- return true ;
201+ // Try TOTP code first, if it's 6 chars. it will throw errors if it's not 6 chars
202+ // and the backup codes are 8 chars.
203+ if ( token . length === 6 ) {
204+ const result = await verify ( {
205+ token,
206+ secret,
207+ } ) ;
208+
209+ if ( result . valid ) {
210+ return true ;
211+ }
209212 }
210213
211214 // Try backup codes
212215 const backupCodes = auth ?. meta ?. backup_codes || [ ] ;
213216 for ( let i = 0 ; i < backupCodes . length ; i ++ ) {
214- const match = await bcrypt . compare ( code . toUpperCase ( ) , backupCodes [ i ] ) ;
217+ const match = await bcrypt . compare ( token . toUpperCase ( ) , backupCodes [ i ] ) ;
215218 if ( match ) {
216219 // Remove used backup code
217220 const updatedCodes = [ ...backupCodes ] ;
Original file line number Diff line number Diff line change 1717 },
1818 "code" : {
1919 "minLength" : 6 ,
20- "maxLength" : 6 ,
20+ "maxLength" : 8 ,
2121 "type" : " string" ,
2222 "example" : " 012345"
2323 }
Original file line number Diff line number Diff line change 1616 }
1717 ],
1818 "requestBody" : {
19- "description" : " Verififcation Payload" ,
19+ "description" : " Verification Payload" ,
2020 "required" : true ,
2121 "content" : {
2222 "application/json" : {
2525 "properties" : {
2626 "code" : {
2727 "minLength" : 6 ,
28- "maxLength" : 6 ,
28+ "maxLength" : 8 ,
2929 "type" : " string" ,
3030 "example" : " 123456"
3131 }
Original file line number Diff line number Diff line change 1616 }
1717 ],
1818 "requestBody" : {
19- "description" : " Verififcation Payload" ,
19+ "description" : " Verification Payload" ,
2020 "required" : true ,
2121 "content" : {
2222 "application/json" : {
2525 "properties" : {
2626 "code" : {
2727 "minLength" : 6 ,
28- "maxLength" : 6 ,
28+ "maxLength" : 8 ,
2929 "type" : " string" ,
3030 "example" : " 123456"
3131 }
You can’t perform that action at this time.
0 commit comments