X-Git-Url: https://gitweb.ps.run/ps-cgit/blobdiff_plain/a431326e8fab8153905fbde036dd3c9fb4cc8eaa..d88ec849c4f7af41a8a41af1a4f79a2b4d41717a:/filters/simple-authentication.lua diff --git a/filters/simple-authentication.lua b/filters/simple-authentication.lua index 9291302..de34d09 100644 --- a/filters/simple-authentication.lua +++ b/filters/simple-authentication.lua @@ -12,17 +12,27 @@ -- -- +-- A list of password protected repositories along with the users who can access them. local protected_repos = { glouglou = { laurent = true, jason = true }, qt = { jason = true, bob = true } } +-- Please note that, in production, you'll want to replace this simple lookup +-- table with either a table of salted and hashed passwords (using something +-- smart like scrypt), or replace this table lookup with an external support, +-- such as consulting your system's pam / shadow system, or an external +-- database, or an external validating web service. For testing, or for +-- extremely low-security usage, you may be able, however, to get away with +-- compromising on hardcoding the passwords in cleartext, as we have done here. local users = { jason = "secretpassword", laurent = "s3cr3t", bob = "ilikelua" } +-- All cookies will be authenticated based on this secret. Make it something +-- totally random and impossible to guess. It should be large. local secret = "BE SURE TO CUSTOMIZE THIS STRING TO SOMETHING BIG AND RANDOM" @@ -36,7 +46,7 @@ local secret = "BE SURE TO CUSTOMIZE THIS STRING TO SOMETHING BIG AND RANDOM" -- Sets HTTP cookie headers based on post and sets up redirection. function authenticate_post() local password = users[post["username"]] - local redirect = validate_value(post["redirect"]) + local redirect = validate_value("redirect", post["redirect"]) if redirect == nil then not_found() @@ -50,7 +60,7 @@ function authenticate_post() set_cookie("cgitauth", "") else -- One week expiration time - local username = secure_value(post["username"], os.time() + 604800) + local username = secure_value("username", post["username"], os.time() + 604800) set_cookie("cgitauth", username) end @@ -67,7 +77,7 @@ function authenticate_cookie() return 1 end - local username = validate_value(get_cookie(http["cookie"], "cgitauth")) + local username = validate_value("username", get_cookie(http["cookie"], "cgitauth")) if username == nil or not accepted_users[username:lower()] then return 0 else @@ -82,7 +92,7 @@ function body() html_attr(cgit["login"]) html("'>") html("") html("