diff options
author | dan <[email protected]> | 2024-04-28 12:12:03 -0400 |
---|---|---|
committer | dan <[email protected]> | 2024-04-28 12:12:03 -0400 |
commit | 18ae691429af89d9949d6e30650d70e3ab4239cb (patch) | |
tree | dd7baee36f6924dd6210de552fcce2c3fe9ad69c /main.scm | |
parent | 4a0316c7970c59937d73744e482acaa524a6741b (diff) | |
download | 54-18ae691429af89d9949d6e30650d70e3ab4239cb.tar.gz 54-18ae691429af89d9949d6e30650d70e3ab4239cb.tar.bz2 54-18ae691429af89d9949d6e30650d70e3ab4239cb.zip |
feat: users are stored in db
Diffstat (limited to 'main.scm')
-rw-r--r-- | main.scm | 20 |
1 files changed, 16 insertions, 4 deletions
@@ -112,13 +112,25 @@ (define (parent-id p) (fifth p)) (define (children-count p) (sixth p)) -(define users (alist->hash-table `(("example" . ,(crypt "pw"))))) - (define apikeys (make-hash-table)) +(define (get-pw-hash-from-db user-id) + (let ([pw-hash-row (condition-case (first-row db + "SELECT pw_hash + FROM users + WHERE user_id = ? + LIMIT 1" + user-id) + [(exn sqlite3) #f])]) + (and pw-hash-row + (list? pw-hash-row) + (not (sql-null? (car pw-hash-row))) + (car pw-hash-row)) + )) + (define (login username password) - (let ([pw-hash-in-db (hash-table-ref/default users username #f)]) - (and password (string=? (crypt password pw-hash-in-db) pw-hash-in-db) + (let ([pw-hash-in-db (get-pw-hash-from-db username)]) + (and password pw-hash-in-db (string=? (crypt password pw-hash-in-db) pw-hash-in-db) (let ([apikey (number->string (pseudo-random-integer 340282366920938463463374607431768211455))]) (hash-table-set! apikeys apikey username) apikey)))) |