commit 55bd4e47f8e2b4fdb800927c71b83edb47432cb6
parent d727095c1bdffc9700ca657bc8bd88af44929949
Author: Antoine A <>
Date: Tue, 15 Oct 2024 13:32:39 +0200
bank: optional prompt for password change
Diffstat:
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/bank/build.gradle b/bank/build.gradle
@@ -25,6 +25,7 @@ dependencies {
implementation("org.postgresql:postgresql:$postgres_version")
implementation("com.github.ajalt.clikt:clikt:$clikt_version")
+ implementation("com.github.ajalt.mordant:mordant:3.0.0")
implementation("io.ktor:ktor-server-core:$ktor_version")
implementation("io.ktor:ktor-server-netty:$ktor_version")
diff --git a/bank/src/main/kotlin/tech/libeufin/bank/cli/ChangePw.kt b/bank/src/main/kotlin/tech/libeufin/bank/cli/ChangePw.kt
@@ -21,14 +21,16 @@ package tech.libeufin.bank.cli
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
-import com.github.ajalt.clikt.parameters.arguments.argument
+import com.github.ajalt.clikt.parameters.arguments.*
import com.github.ajalt.clikt.parameters.groups.provideDelegate
+import com.github.ajalt.clikt.parameters.options.*
import tech.libeufin.bank.bankConfig
import tech.libeufin.bank.db.AccountDAO.AccountPatchAuthResult
import tech.libeufin.bank.logger
import tech.libeufin.bank.withDb
import tech.libeufin.common.CommonOption
import tech.libeufin.common.cliCmd
+import com.github.ajalt.mordant.terminal.*
class ChangePw : CliktCommand("passwd") {
override fun help(context: Context) = "Change account password"
@@ -38,8 +40,25 @@ class ChangePw : CliktCommand("passwd") {
private val password by argument(
"password",
help = "Account password used for authentication"
- )
-
+ ).defaultLazy("prompt") {
+ val terminal = Terminal()
+ ConfirmationPrompt.create(
+ "Password",
+ "Repeat for confirmation",
+ "Values do not match, try again",
+ {
+ object : Prompt<String>(
+ prompt = it,
+ terminal = terminal,
+ hideInput = true
+ ) {
+ override fun convert(input: String): ConversionResult<String> {
+ return ConversionResult.Valid(input)
+ }
+ }
+ }
+ ).ask()!!
+ }
override fun run() = cliCmd(logger, common.log) {
bankConfig(common.config).withDb { db, cfg ->
val res = db.account.reconfigPassword(username, password, null, true, cfg.pwCrypto)