diff --git a/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/SetOTPDialogFragment.kt b/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/SetOTPDialogFragment.kt index 32bccfc76..ef56e248c 100644 --- a/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/SetOTPDialogFragment.kt +++ b/app/src/main/java/com/kunzisoft/keepass/activities/dialogs/SetOTPDialogFragment.kt @@ -41,6 +41,7 @@ import com.kunzisoft.keepass.otp.OtpElement.Companion.MAX_TOTP_PERIOD import com.kunzisoft.keepass.otp.OtpElement.Companion.MIN_HOTP_COUNTER import com.kunzisoft.keepass.otp.OtpElement.Companion.MIN_OTP_DIGITS import com.kunzisoft.keepass.otp.OtpElement.Companion.MIN_TOTP_PERIOD +import com.kunzisoft.keepass.otp.OtpElement.Companion.MIN_OTP_SECRET import com.kunzisoft.keepass.otp.OtpTokenType import com.kunzisoft.keepass.otp.OtpType import com.kunzisoft.keepass.otp.TokenCalculator @@ -312,8 +313,9 @@ class SetOTPDialogFragment : DatabaseDialogFragment() { // Set secret in OtpElement otpSecretTextView?.addTextChangedListener(object: TextWatcher { override fun afterTextChanged(s: Editable?) { - s?.toString()?.let { userString -> - if (userString.length >= 8) { + s?.toString()?.let { userString -> + + if (userString.length >= MIN_OTP_SECRET) { try { mOtpElement.setBase32Secret(userString.uppercase(Locale.ENGLISH)) otpSecretContainer?.error = null @@ -321,7 +323,8 @@ class SetOTPDialogFragment : DatabaseDialogFragment() { otpSecretContainer?.error = getString(R.string.error_otp_secret_key) } } else { - otpSecretContainer?.error = null + otpSecretContainer?.error = getString(R.string.error_otp_secret_length, + MIN_OTP_SECRET) } mSecretWellFormed = otpSecretContainer?.error == null } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index db640445e..1845b62a8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -187,6 +187,7 @@ Unable to create database with this password and keyfile. Could not save the database. Secret key must be in Base32 format. + Secret key must be at least %1$d characters. Counter must be between %1$d and %2$d. Period must be between %1$d and %2$d seconds. Token must contain %1$d to %2$d digits. diff --git a/database/src/main/java/com/kunzisoft/keepass/otp/OtpElement.kt b/database/src/main/java/com/kunzisoft/keepass/otp/OtpElement.kt index e98740fd6..5e3d4a016 100644 --- a/database/src/main/java/com/kunzisoft/keepass/otp/OtpElement.kt +++ b/database/src/main/java/com/kunzisoft/keepass/otp/OtpElement.kt @@ -216,6 +216,8 @@ data class OtpElement(var otpModel: OtpModel = OtpModel()) { const val MIN_OTP_DIGITS = 4 const val MAX_OTP_DIGITS = 18 + const val MIN_OTP_SECRET = 8 + fun isValidCounter(counter: Long): Boolean { return counter in MIN_HOTP_COUNTER..MAX_HOTP_COUNTER }