antibot - basic pow with javascript

This commit is contained in:
bunkerity
2021-05-19 17:36:29 +02:00
parent 16e5ede130
commit 6645632846
3 changed files with 19 additions and 8 deletions

View File

@@ -32,12 +32,15 @@ function M.get_code (challenge, antibot_uri, original_uri)
end
function M.check (challenge, user)
ngx.log(ngx.ERR, "debug challenge = " .. challenge)
ngx.log(ngx.ERR, "debug user = " .. user)
local resty_sha256 = require "resty.sha256"
local str = require "resty.string"
local sha256 = resty_sha256:new()
sha256:update(challenge)
sha256:update(challenge .. user)
local digest = sha256:final()
return str.to_hex(digest) == user
ngx.log(ngx.ERR, "debug digest = " .. str.to_hex(digest))
return str.to_hex(digest):find("^0000") ~= nil
end
return M