From f803465e403c43615d5ad134d4b6cd17c4a89917 Mon Sep 17 00:00:00 2001 From: Alexander Grahn Date: Sun, 11 Aug 2024 22:27:20 +0200 Subject: add user ID input field (password creation/edit), may fix #1458 (#3161) * add user ID input field (password creation/edit), may fix #1458 * fix: revert change to username label * refactor: rework FieldItem to drop hard-coded strings * refactor: drop unnecessary `.apply` --------- Co-authored-by: Harsh Shandilya --- .../app/passwordstore/data/passfile/PasswordEntry.kt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'format/common/src') diff --git a/format/common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt b/format/common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt index cd152c9a..aeaa745b 100644 --- a/format/common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt +++ b/format/common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt @@ -80,6 +80,9 @@ constructor( return otp.value.value } + /** String representation of [extraContent] but with usernames stripped. */ + public val extraContentWithoutUsername: String + /** * String representation of [extraContent] but with authentication related data such as TOTP URIs * and usernames stripped. @@ -91,6 +94,7 @@ constructor( val (foundPassword, passContent) = findAndStripPassword(content.split("\n".toRegex())) password = foundPassword extraContentString = passContent.joinToString("\n") + extraContentWithoutUsername = generateExtraContentWithoutUsername() extraContentWithoutAuthData = generateExtraContentWithoutAuthData() extraContent = generateExtraContentPairs() username = findUsername() @@ -121,7 +125,7 @@ constructor( return Pair(passContent[0], passContent.minus(passContent[0])) } - private fun generateExtraContentWithoutAuthData(): String { + private fun generateExtraContentWithoutUsername(): String { var foundUsername = false return extraContentString .lineSequence() @@ -132,6 +136,19 @@ constructor( foundUsername = true false } + else -> { + true + } + } + } + .joinToString(separator = "\n") + } + + private fun generateExtraContentWithoutAuthData(): String { + return generateExtraContentWithoutUsername() + .lineSequence() + .filter { line -> + return@filter when { TotpFinder.TOTP_FIELDS.any { prefix -> line.startsWith(prefix, ignoreCase = true) } -> { false } -- cgit v1.2.3