Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Fix manual OTP configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
M3DZIK committed Feb 28, 2024
1 parent 156aebe commit 18f5a3c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ enum class Screen(
customScaffold = true,
composable = { CipherEditScreen(it) }
),
TotpConfigure(
ConfigureOtp(
args = arrayOf(Argument.CipherId),
customScaffold = true,
composable = { OtpConfigure(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fun CipherEditFieldsLogin(
Button(
onClick = {
navController.navigate(
screen = Screen.TotpConfigure,
screen = Screen.ConfigureOtp,
args = arrayOf(Argument.CipherId to cipher.id.toString())
)
},
Expand All @@ -188,7 +188,7 @@ fun CipherEditFieldsLogin(
.padding(horizontal = 60.dp)
.padding(top = 8.dp)
) {
Text(stringResource(R.string.TotpConfigure))
Text(stringResource(R.string.ConfigureOtp))
}

if (!cipher.loginData?.twoFactor.isNullOrEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun OtpConfigure(
Scaffold(
topBar = {
TopBar(
title = stringResource(R.string.TotpConfigure),
title = stringResource(R.string.ConfigureOtp),
navigationIcon = { TopBarBackIcon(navController) }
)
}
Expand Down Expand Up @@ -108,9 +108,7 @@ fun OtpConfigure(
text = stringResource(R.string.Error_InvalidURI),
color = MaterialTheme.colorScheme.error,
fontSize = 18.sp,
modifier =
Modifier
.padding(6.dp),
modifier = Modifier.padding(6.dp)
)
}
}
Expand Down Expand Up @@ -149,7 +147,7 @@ fun OtpConfigure(
beginParams = OTPParser.parse(cipher.loginData?.twoFactor)
}

var totpSecret by rememberMutable(beginParams?.secret?.value?.toString() ?: "")
var totpSecret by rememberMutable(beginParams?.secret?.encoded?.toString() ?: "")

var digits by rememberMutable(beginParams?.digits?.value?.toString() ?: "6")
var type by rememberMutable(beginParams?.type ?: OTPType.TOTP)
Expand All @@ -159,7 +157,7 @@ fun OtpConfigure(
var counter by rememberMutable(beginParams?.counter?.value?.toString() ?: "0")

TextInputFieldBase(
label = stringResource(R.string.TotpKey),
label = stringResource(R.string.TwoFactorSecret),
modifier =
Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -218,7 +216,7 @@ fun OtpConfigure(
var otpUri by rememberMutable("")
val otpCodeError =
runCatching {
otpUri = calculateOtpCode(totpSecret, type, digits.toInt(), period.toInt(), counter.toLong())
otpUri = generateOtpUri(totpSecret, type, digits.toInt(), period.toInt(), counter.toLong())
}.isSuccess

Button(
Expand Down Expand Up @@ -251,7 +249,7 @@ fun OtpConfigure(
}
}

fun calculateOtpCode(
fun generateOtpUri(
secret: String,
type: OTPType,
digits: Int,
Expand Down
7 changes: 3 additions & 4 deletions app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,14 @@
<string name="WebsiteDetails">Strona internetowa</string>
<string name="WelcomeScreen_Title">Witaj w LibrePass</string>
<string name="optional">opcjonalnie</string>
<string name="TwoFactorAuthentication">Uwierzytelnianie dwuskładnikowe</string>
<string name="TwoFactorSecret">Sekret dwuskładnikowego logowania</string>
<string name="TotpKey">Klucz uwierzytelniania (TOTP)</string>
<string name="TwoFactorAuthentication">Uwierzytelnianie dwuetapowe</string>
<string name="TwoFactorSecret">Sekret dwuetapowego logowania</string>
<string name="Error_InvalidURI">Adres URI jest nieprawidłowy</string>
<string name="CardDetails">Dane karty</string>
<string name="BiometricKeyInvalidated">Klucz biometryczny został unieważniony przez Androida</string>
<string name="NewEmail">Nowy adres e-mail</string>
<string name="ChangeEmail">Zmień adres e-mail</string>
<string name="TotpConfigure">Skonfiguruj TOTP</string>
<string name="ConfigureOtp">Skonfiguruj 2fa</string>
<string name="ScanQrCode">Zeskanuj kod QR</string>
<string name="EnterKeyManually">Wprowadź klucz manualnie</string>
<string name="DeleteTotp">Usuń TOTP</string>
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<string name="AddServer">Add server</string>
<string name="TwoFactorAuthentication">Two-factor authentication</string>
<string name="TwoFactorSecret">Two-factor secret</string>
<string name="TotpKey">Authentication Key (TOTP)</string>
<string name="BiometricSetup_Button_Cancel">Cancel</string>
<string name="BiometricSetup_Subtitle">Turn on biometric authentication</string>
<string name="BiometricSetup_Title">Setup</string>
Expand Down Expand Up @@ -113,7 +112,7 @@
<string name="InvalidToken">Invalid login token</string>
<string name="RateLimit">Too many requests</string>
<string name="SendEmail">Internal server error - Failed to send email</string>
<string name="TotpConfigure">Configure TOTP</string>
<string name="ConfigureOtp">Configure two-factor</string>
<string name="ScanQrCode">Scan QR code</string>
<string name="EnterKeyManually">Enter key manually</string>
<string name="DeleteTotp">Delete TOTP</string>
Expand Down

0 comments on commit 18f5a3c

Please sign in to comment.