GNU Artanis provides flexible mechanism for authentication.
You can use #:auth mode
to define a URL rule handler.
(get "/certain-rule" #:auth mode (lambda (rc) ...))
mode can be:
('basic (lambda (rc user passwd) ...))
init Basic Authentication mode. user is the username, and passwd is the password.
('table table-name username-field passwd-field)
init a common Authentication mode. The passwd will be encrypted by the default algorithm.
('table table-name username-field passwd-field crypto-proc)
similar to the above item, but encrypt passwd with crypto-proc.
(table-name crypto-proc)
, so the passwd field will be "passwd" and username will be "username" by default.You can encrypt the passwd with crypto-proc.
Available crypto-proc helper functions listed here:
(string->md5 <string>) (string->sha-1 <string>) (string->sha-224 <string>) (string->sha-256 <string>) (string->sha-384 <string>) (string->sha-512 <string>)
NOTE: Please make sure that the username-field
and passwd-field
must be the same with the field name specifed in the submit form of you web page code.
For example, if there is a form on you page:
<input type="password" name="passwd">
Please notice that name of password input was specified to "passwd"
.
Then you should write authentication like this:
(post "/auth" #:auth '(table user "user" "passwd") #:session #t (lambda (rc) ...))
Please notice that the "passwd"
here is the same with what you specified in the form.