libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

commit ebb2b8787936d98590baaef37865e6b720b75bb7
parent 12fa142a6b573e75c93d8e796b7e0ce4e6086344
Author: Florian Dold <florian@dold.me>
Date:   Mon, 25 Sep 2023 19:44:07 +0200

implement password change subcommand

Diffstat:
MMakefile | 3++-
Mbank/src/main/kotlin/tech/libeufin/bank/Database.kt | 11+++++++++++
Mbank/src/main/kotlin/tech/libeufin/bank/Main.kt | 33++++++++++++++++++++++++++++++++-
3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -40,7 +40,8 @@ deb: exec-arch copy-spa .PHONY: install-bank install-bank: - @install -D contrib/libeufin-bank.conf $(config_dir) + install -d $(config_dir) + install contrib/libeufin-bank.conf $(config_dir)/ @./gradlew -q -Pprefix=$(prefix) bank:installToPrefix; cd .. # To reactivate after the refactoring. diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Database.kt b/bank/src/main/kotlin/tech/libeufin/bank/Database.kt @@ -241,6 +241,17 @@ class Database(private val dbConfig: String, private val bankCurrency: String) { } } + fun customerChangePassword(customerName: String, passwordHash: String): Boolean { + reconnect() + val stmt = prepare(""" + UPDATE customers SET password_hash=? where login=? + """) + stmt.setString(1, passwordHash) + stmt.setString(2, customerName) + stmt.executeUpdate() + return stmt.updateCount > 0 + } + fun customerGetFromLogin(login: String): Customer? { reconnect() val stmt = prepare(""" diff --git a/bank/src/main/kotlin/tech/libeufin/bank/Main.kt b/bank/src/main/kotlin/tech/libeufin/bank/Main.kt @@ -27,6 +27,7 @@ import com.github.ajalt.clikt.parameters.options.* import com.github.ajalt.clikt.core.context import com.github.ajalt.clikt.core.subcommands import com.github.ajalt.clikt.output.CliktHelpFormatter +import com.github.ajalt.clikt.parameters.arguments.argument import com.github.ajalt.clikt.parameters.options.versionOption import io.ktor.http.* import io.ktor.server.application.* @@ -294,7 +295,7 @@ fun Application.corebankWebApp(db: Database, ctx: BankApplicationContext) { class LibeufinBankCommand : CliktCommand() { init { versionOption(getVersion()) - subcommands(ServeBank(), BankDbInit()) + subcommands(ServeBank(), BankDbInit(), ChangePw()) } override fun run() = Unit @@ -449,6 +450,36 @@ class ServeBank : CliktCommand("Run libeufin-bank HTTP server", name = "serve") } } +class ChangePw : CliktCommand("Change account password", name = "passwd") { + private val configFile by option( + "--config", "-c", + help = "set the configuration file" + ) + private val account by argument("account") + private val password by argument("password") + init { + context { + helpFormatter = CliktHelpFormatter(showDefaultValues = true) + } + } + + override fun run() { + val config = TalerConfig.load(this.configFile) + val ctx = readBankApplicationContextFromConfig(config) + val dbConnStr = config.requireValueString("libeufin-bankdb-postgres", "config") + val servePortLong = config.requireValueNumber("libeufin-bank", "port") + val db = Database(dbConnStr, ctx.currency) + if (!maybeCreateAdminAccount(db, ctx)) // logs provided by the helper + exitProcess(1) + + if (!db.customerChangePassword(account, CryptoUtil.hashpw(password))) { + println("password change failed") + } else { + println("password change succeeded") + } + } +} + fun main(args: Array<String>) { LibeufinBankCommand().main(args) }