gpt4 book ai didi

sinatra - Sinatra 的验证码是什么?

转载 作者:行者123 更新时间:2023-12-02 10:43:58 26 4
gpt4 key购买 nike

您在 Sinatra 应用程序中使用什么验证码?

我喜欢 Google 的 http://www.google.com/recaptcha ,但似乎不适用于 Sinatra(不过有一个 Rails 插件)。经过谷歌搜索后,插件如 https://github.com/jpoz/sinatra-recaptchahttps://github.com/bmizerany/sinatra-captcha好像永远都是5岁……

谢谢!

最佳答案

在没有任何插件的情况下使用 reCaptcha 并不难。请参阅here for how to display reCaptcha without pluginshere for how to verify the user's answer 。 API 非常简单。当用户解决验证码时,将提交两个参数:recaptcha_challenge_fieldrecaptcha_response_field。您可以使用这些从服务器调用验证 API 并检查解决方案是否正确。例如:

require 'net/http'
require 'json'

post '/check_captcha' do
res = Net::HTTP.post_form(
URI.parse('http://www.google.com/recaptcha/api/verify'),
{
'privatekey' => 'Your private key',
'remoteip' => request.ip,
'challenge' => params[:recaptcha_challenge_field],
'response' => params[:recaptcha_response_field]
}
)

success, error_key = res.body.lines.map(&:chomp)

if success == 'true'
# solved the captcha
else
# did not solve the captcha
end
end

关于sinatra - Sinatra 的验证码是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21262254/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com