summaryrefslogtreecommitdiffstats
path: root/add-user.scm
diff options
context:
space:
mode:
authordan <[email protected]>2024-04-28 12:12:03 -0400
committerdan <[email protected]>2024-04-28 12:12:03 -0400
commit18ae691429af89d9949d6e30650d70e3ab4239cb (patch)
treedd7baee36f6924dd6210de552fcce2c3fe9ad69c /add-user.scm
parent4a0316c7970c59937d73744e482acaa524a6741b (diff)
download54-18ae691429af89d9949d6e30650d70e3ab4239cb.tar.gz
54-18ae691429af89d9949d6e30650d70e3ab4239cb.tar.bz2
54-18ae691429af89d9949d6e30650d70e3ab4239cb.zip
feat: users are stored in db
Diffstat (limited to 'add-user.scm')
-rw-r--r--add-user.scm28
1 files changed, 28 insertions, 0 deletions
diff --git a/add-user.scm b/add-user.scm
new file mode 100644
index 0000000..9799bf5
--- /dev/null
+++ b/add-user.scm
@@ -0,0 +1,28 @@
+(import
+ scheme (chicken base)
+ (chicken process-context)
+ sqlite3
+ crypt
+ srfi-1
+)
+
+(define params (argv))
+(define username (second params))
+(define password (third params))
+(define password-hash (crypt password))
+
+(define db (open-database (or (get-environment-variable "DB_FILE") "/tmp/54itter.db")))
+
+(execute db "CREATE TABLE IF NOT EXISTS users (
+ user_id TEXT PRIMARY KEY,
+ pw_hash TEXT,
+ created_at DATETIME default current_timestamp
+ )")
+
+(execute db "INSERT INTO users
+ (user_id, pw_hash)
+ VALUES (?, ?)"
+ username password-hash)
+(finalize! db)
+
+(print "Created user " username)