aboutsummaryrefslogtreecommitdiff
path: root/format/common
diff options
context:
space:
mode:
authorAlexander Grahn <agrahn@users.noreply.github.com>2024-08-11 22:27:20 +0200
committerGitHub <noreply@github.com>2024-08-11 20:27:20 +0000
commitf803465e403c43615d5ad134d4b6cd17c4a89917 (patch)
tree04173405dd4362d1d586faab9012def41d1fd061 /format/common
parentd62516399e36be62a282d4be305381f9e1703fc7 (diff)
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 <me@msfjarvis.dev>
Diffstat (limited to 'format/common')
-rw-r--r--format/common/src/main/kotlin/app/passwordstore/data/passfile/PasswordEntry.kt19
1 files changed, 18 insertions, 1 deletions
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
}