;;;; SPDX-FileCopyrightText: 2023 Vasilij Schneidermann ;;;; ;;;; SPDX-License-Identifier: GPL-3.0-or-later (module modo-generate-user () (import scheme) (import (chicken base)) (import (chicken io)) (import (chicken process-context)) (import (chicken time posix)) (import crypt) (import sql-de-lite) (import stty) (define stdin (current-input-port)) (define stdout (current-output-port)) (define (read-input prompt) (display prompt stdout) (flush-output stdout) (read-line stdin)) (define (read-password prompt) (display prompt stdout) (flush-output stdout) (let ((line (with-stty '(not echo) (lambda () (read-line stdin))))) (newline stdout) line)) (define (utc-timestamp) (time->string (seconds->utc-time) "%Y%m%dT%H%M%SZ")) (define (main db-path) (call-with-database db-path (lambda (db) (let ((username (read-input "Username: "))) (when username (let* ((password (read-password "Password: ")) (confirmation (read-password "Confirm password: "))) (when (and password confirmation (equal? password confirmation)) (let ((timestamp (utc-timestamp)) (hash (crypt password (crypt-gensalt type: 'blowfish)))) (exec (sql db "INSERT INTO users(username, password, created, updated) VALUES(?, ?, ?, ?)") username hash timestamp timestamp) (print "User " username " successfully created"))))))))) (apply main (command-line-arguments)) )