Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
30 lines (26 loc) · 988 Bytes

File metadata and controls

30 lines (26 loc) · 988 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
-- httpserver-basicauth.lua
-- Part of nodemcu-httpserver, authenticates a user using http basic auth.
-- Author: Sam Dieck
basicAuth = {}
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 credentials_enc = header:match("Authorization: Basic ([A-Za-z0-9+/=]+)")
if not credentials_enc then
return nil
end
--local credentials = dofile("httpserver-b64decode.lc")(credentials_enc)
local credentials=require("base64dec").dec(credentials_enc)
local user, pwd = credentials:match("^(.*):(.*)$")
if user ~= conf.auth.user or pwd ~= conf.auth.password then
return nil
end
--print("httpserver-basicauth: User \"" .. user .. "\" authenticated.")
return user
end
function basicAuth.authErrorHeader()
return "WWW-Authenticate: Basic realm=\"" .. conf.auth.realm .. "\""
end
return basicAuth
Morty Proxy This is a proxified and sanitized view of the page, visit original site.