lachlanbell / SwiftOTP

A Swift library for generating One Time Passwords (OTP)
MIT License
285 stars 59 forks source link

Number of Digits #22

Closed bander-saeed94 closed 4 years ago

bander-saeed94 commented 4 years ago

I notice it only accept range 6...8

I believe it should accept 4 since it is a common case

lachlanbell commented 4 years ago

Hi, thanks for the suggestion. The minimum number of digits is set at 6, as this implementation follows the OTP specification—RFC4226—which states:

The HOTP value must be at least a 6-digit value.

I'm curious to see examples of 4-digit OTPs in use. If you want to use shorter passwords in your specific use case, the digit length is only a soft limit, so you can modify these lines: https://github.com/lachlanbell/SwiftOTP/blob/b45615e2dec54bde1d00f75f4e325685946ccf91/SwiftOTP/HOTP.swift#L67 https://github.com/lachlanbell/SwiftOTP/blob/b45615e2dec54bde1d00f75f4e325685946ccf91/SwiftOTP/TOTP.swift#L78