This repository was archived by the owner on Feb 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.lisp
More file actions
46 lines (38 loc) · 1.26 KB
/
auth.lisp
File metadata and controls
46 lines (38 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(in-package #:hacksthenet)
(defclass account ()
((username :type string
:initarg :username
:accessor username)
(password :type string
:initarg :password
:accessor password)))
(defvar *accounts* ())
(defun find-account (username)
(find-if (lambda (acc)
(string= username
(username acc)))
*accounts*))
(defun add-account (username password)
(unless (find-account username)
(let ((account (make-instance 'account
:username username
:password password)))
(push account
*accounts*)
account)))
(defun login (username password)
"Log in if the username and password matches an account.
Return the account if successful; NIL otherwise."
(let ((account (find-account username)))
(and account
(string= password (password account))
(setf (session-value 'account) account))))
(defun change-pass (username password)
(let ((account (find-account username)))
(when account
(setf (password account) password))))
(defun session-account ()
(session-value 'account))
(defun add-account* (username password)
(setf (session-value 'account)
(add-account username password)))