# HG changeset patch # User David Barts # Date 1662945895 25200 # Node ID 3c792ad36b3d2f1a0acec3cb2d8da367400af933 # Parent 8aacca5c2d5328fd064c745353d6dd67d7b5cf12 Can now update a password and read it back. diff -r 8aacca5c2d53 -r 3c792ad36b3d src/main/kotlin/name/blackcap/passman/Clipboard.kt --- a/src/main/kotlin/name/blackcap/passman/Clipboard.kt Sun Sep 11 16:12:47 2022 -0700 +++ b/src/main/kotlin/name/blackcap/passman/Clipboard.kt Sun Sep 11 18:24:55 2022 -0700 @@ -31,7 +31,7 @@ } } -/* xxx: this often makes a string out of a password */ +/* XXX: This will make a string out of a password. Shikata ga nai. */ fun writeToClipboard(charArray: CharArray) { CLIPBOARD.setContents(ClipboardData(String(charArray)), ClipboardOwner()) } diff -r 8aacca5c2d53 -r 3c792ad36b3d src/main/kotlin/name/blackcap/passman/Entry.kt --- a/src/main/kotlin/name/blackcap/passman/Entry.kt Sun Sep 11 16:12:47 2022 -0700 +++ b/src/main/kotlin/name/blackcap/passman/Entry.kt Sun Sep 11 18:24:55 2022 -0700 @@ -17,18 +17,22 @@ ) fun withGeneratedPassword(length: Int, allowSymbols: Boolean, verbose: Boolean): Entry { - val generated = generate(length, allowSymbols) - if (verbose) { - println("Generated password: $generated") - } return Entry( name = _getName(), username = _getUsername(), - password = generated, + password = _genPassword(length, allowSymbols, verbose), notes = _getNotes() ) } + private fun _genPassword(length: Int, allowSymbols: Boolean, verbose: Boolean): CharArray { + val generated = generate(length, allowSymbols) + if (verbose) { + printPassword(generated) + } + return generated + } + private fun _getName() = mustReadLine("Name of site: ") private fun _getUsername() = mustReadLine("Username: ") diff -r 8aacca5c2d53 -r 3c792ad36b3d src/main/kotlin/name/blackcap/passman/UpdateSubcommand.kt --- a/src/main/kotlin/name/blackcap/passman/UpdateSubcommand.kt Sun Sep 11 16:12:47 2022 -0700 +++ b/src/main/kotlin/name/blackcap/passman/UpdateSubcommand.kt Sun Sep 11 18:24:55 2022 -0700 @@ -97,14 +97,18 @@ private fun update(): Unit { updateOne("username") - updateOne("password") + if (generate) { + generatePassword() + } else { + updateOne("password") + } updateOne("notes") if (fieldValues.isEmpty()) { error("no values changed") return } - db.connection.prepareStatement("update passwords set updated = ?, $fields where id = ?").use { stmt -> + db.connection.prepareStatement("update passwords set modified = ?, $fields where id = ?").use { stmt -> stmt.setLong(1, System.currentTimeMillis()) fieldValues.indices.forEach { fieldIndex -> val fieldValue = fieldValues[fieldIndex] @@ -127,7 +131,11 @@ getPassword(prompt, verify = true) } else { val rawValue = readLine(prompt) - if (name in NULLABLE_FIELDS && rawValue == NULL_SPECIFIED) { null } else { rawValue } + if (name in NULLABLE_FIELDS && rawValue == NULL_SPECIFIED) { + null + } else { + rawValue + } } val noChange = when (value) { @@ -139,6 +147,10 @@ return } + addOne(name, value) + } + + private fun addOne(name: String, value: Any?) { if (fields.isNotEmpty()) { fields.append(", ") } @@ -147,4 +159,12 @@ fieldValues.add(value) } + private fun generatePassword(): Unit { + val newPassword = generate(length, allowSymbols) + if (verbose) { + printPassword(newPassword) + } + addOne("password", newPassword) + } + } \ No newline at end of file