From 37e58389c67dcf0bbe9ffc0b8a716a8f3decb61a Mon Sep 17 00:00:00 2001 From: Marcos Kirsch Date: Mon, 15 Feb 2016 13:46:50 -0600 Subject: [PATCH] Trivial improvement to print message --- httpserver-basicauth.lua | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/httpserver-basicauth.lua b/httpserver-basicauth.lua index 8ff7d25..09d4f78 100644 --- a/httpserver-basicauth.lua +++ b/httpserver-basicauth.lua @@ -4,11 +4,11 @@ basicAuth = {} +-- Parse basic auth http header. +-- Returns the username if header contains valid credentials, +-- nil otherwise. function basicAuth.authenticate(header) - conf = dofile("httpserver-conf.lc") - -- Parse basic auth http header. - -- Returns the username if header contains valid credentials, - -- nil otherwise. + local conf = dofile("httpserver-conf.lc") local credentials_enc = header:match("Authorization: Basic ([A-Za-z0-9+/=]+)") if not credentials_enc then return nil @@ -16,13 +16,15 @@ function basicAuth.authenticate(header) local credentials = dofile("httpserver-b64decode.lc")(credentials_enc) local user, pwd = credentials:match("^(.*):(.*)$") if user ~= conf.auth.user or pwd ~= conf.auth.password then + print("httpserver-basicauth: User \"" .. user .. "\": Access denied.") return nil end - print("httpserver-basicauth: User \"" .. user .. "\" authenticated.") + print("httpserver-basicauth: User \"" .. user .. "\": Authenticated.") return user end function basicAuth.authErrorHeader() + local conf = dofile("httpserver-conf.lc") return "WWW-Authenticate: Basic realm=\"" .. conf.auth.realm .. "\"" end