Trivial improvement to print message
This commit is contained in:
parent
0e4b515514
commit
37e58389c6
@ -4,11 +4,11 @@
|
|||||||
|
|
||||||
basicAuth = {}
|
basicAuth = {}
|
||||||
|
|
||||||
|
-- Parse basic auth http header.
|
||||||
|
-- Returns the username if header contains valid credentials,
|
||||||
|
-- nil otherwise.
|
||||||
function basicAuth.authenticate(header)
|
function basicAuth.authenticate(header)
|
||||||
conf = dofile("httpserver-conf.lc")
|
local conf = dofile("httpserver-conf.lc")
|
||||||
-- Parse basic auth http header.
|
|
||||||
-- Returns the username if header contains valid credentials,
|
|
||||||
-- nil otherwise.
|
|
||||||
local credentials_enc = header:match("Authorization: Basic ([A-Za-z0-9+/=]+)")
|
local credentials_enc = header:match("Authorization: Basic ([A-Za-z0-9+/=]+)")
|
||||||
if not credentials_enc then
|
if not credentials_enc then
|
||||||
return nil
|
return nil
|
||||||
@ -16,13 +16,15 @@ function basicAuth.authenticate(header)
|
|||||||
local credentials = dofile("httpserver-b64decode.lc")(credentials_enc)
|
local credentials = dofile("httpserver-b64decode.lc")(credentials_enc)
|
||||||
local user, pwd = credentials:match("^(.*):(.*)$")
|
local user, pwd = credentials:match("^(.*):(.*)$")
|
||||||
if user ~= conf.auth.user or pwd ~= conf.auth.password then
|
if user ~= conf.auth.user or pwd ~= conf.auth.password then
|
||||||
|
print("httpserver-basicauth: User \"" .. user .. "\": Access denied.")
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
print("httpserver-basicauth: User \"" .. user .. "\" authenticated.")
|
print("httpserver-basicauth: User \"" .. user .. "\": Authenticated.")
|
||||||
return user
|
return user
|
||||||
end
|
end
|
||||||
|
|
||||||
function basicAuth.authErrorHeader()
|
function basicAuth.authErrorHeader()
|
||||||
|
local conf = dofile("httpserver-conf.lc")
|
||||||
return "WWW-Authenticate: Basic realm=\"" .. conf.auth.realm .. "\""
|
return "WWW-Authenticate: Basic realm=\"" .. conf.auth.realm .. "\""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user