gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] branch master updated: implement password change subcommand


From: gnunet
Subject: [libeufin] branch master updated: implement password change subcommand
Date: Mon, 25 Sep 2023 19:44:16 +0200

This is an automated email from the git hooks/post-receive script.

dold pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new ebb2b878 implement password change subcommand
ebb2b878 is described below

commit ebb2b8787936d98590baaef37865e6b720b75bb7
Author: Florian Dold <florian@dold.me>
AuthorDate: Mon Sep 25 19:44:07 2023 +0200

    implement password change subcommand
---
 Makefile                                           |  3 +-
 .../src/main/kotlin/tech/libeufin/bank/Database.kt | 11 ++++++++
 bank/src/main/kotlin/tech/libeufin/bank/Main.kt    | 33 +++++++++++++++++++++-
 contrib/wallet-core                                |  2 +-
 4 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 7fd05bf0..da0b6874 100644
--- 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
index 960b8d59..110f3a1e 100644
--- 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
index 5d391191..09da3cd8 100644
--- 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)
 }
diff --git a/contrib/wallet-core b/contrib/wallet-core
index c5a3cd4c..9e2d95b3 160000
--- a/contrib/wallet-core
+++ b/contrib/wallet-core
@@ -1 +1 @@
-Subproject commit c5a3cd4c50676c49fa6c67cbdeb609101c38e764
+Subproject commit 9e2d95b39723a038eb714d723ac0910a5bf596e2

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]