- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我环顾四周,没有看到任何特定于 recaptcha 2.0 的内容,所以让我们看看是否可以获得一些帮助。
我正在设置一个包含多个表单的注册/登录页面。为了提高安全性,我正在安装 recaptcha 2.0。
它可以很好地处理单一表单以及在加载时呈现。
对于登录表单,我只想在尝试/限制失败后部署 recaptcha 2.0。
看来我已经在服务器端正确设置了东西,并且我得到了登录延迟和 recaptcha 部署的正确响应。
但是现在正在显示验证码。
我正在尝试关注these instructions
我已经做了多次尝试,包括:- 将验证码持有人设置为 display:none
并且仅在触发时显示- 仅在触发时附加验证码脚本。
我相信问题出在 head 标签上的 recaptcha 配置上,但我不知道如何将其配置为由 ajax 调用触发。
这是我到目前为止所拥有的:
1 - 在 <head>
上显式调用 recaptcha标签:
<script type="text/javascript">
var widgetId1;
var widgetId2;
var onloadCallback = function() {
// Renders the HTML element with id 'example1' as a reCAPTCHA widget.
// The id of the reCAPTCHA widget is assigned to 'widgetId1'.
widgetId1 = grecaptcha.render('captcha_signup', {
'sitekey' : 'mysitekey'
});
widgetId2 = grecaptcha.render('captcha_signin', {
'sitekey' : 'mysitekey'
});
};
</script>
2 - 登录表单:
<div id="login">
<form action="" name="login_form" method="post" id="login_form" >
<div class="contact">
<input id="focus2" data-validation="email" data-validation-error-msg="SVP, tapez un address mail valide" class="inp" name="email" size="35" type="text" placeholder="Votre e-mail" />
</div>
<div class="contact">
<input id="pass_in" type="password" name="pass_confirmation" data-validation="length" data-validation-length="8-15" data-validation-error-msg="SVP minimum 8 caracteres" placeholder="Votre mot de passe" class="inp" size="15" />
</div>
<span id="a_recovery">Mot de passe oubliee?</span>
<div id="captcha_holder"> <div id="captcha_signin" style="display:none"></div> </div>
<div class="form_sub">
<input class="sub inp" name="submit" type="submit" value="Valider" />
</div>
</form>
3 - ajax 调用提交/处理错误/部署 recaptcha
<script>
$(document).ready(function(){
$('#login_form').submit(function(e) {
var str = $("#login_form").serialize();
$.ajax({
url: "used_dataentry.php",
type: "POST",
dataType:"text",
data:'code='+'login'+'&'+str,
success: function (data) {
var msg0 = data.substring(0, 4);
var msg1 = data.substring(4);
if ( msg0 == 'msg4' || msg0 == 'msg5') { //this to show recaptcha
alert(msg0);
$("#captcha_signin").show();
}
else{ alert(msg1)};
}
});
e.preventDefault(); //STOP default action
});
});
</script>
最佳答案
这是我之前的做法。删除 head
中的内容并查看代码片段中的注释以获取更多详细信息。我使用一个可以异步添加脚本的函数(GetScript
或使用 jQuery。)另请注意您需要的要点以及一些变量 WIN = window
和 KEY
是您的 api key 。让我知道这对你有用。
Captcha = function (context) {
/**
* @author (@colecmc)
* @summary google reCaptcha2.0 custom implementation
* @requires jQuery, PubSub @see https://gist.github.com/safe1981/2026701
* @returns {object}
* @param {object} context - jQuery object
* @see https://developers.google.com/recaptcha/docs/display
* @example Captcha(this); // Invoke from jQuery load call back
*/
'use strict';
var container, id, clientId;
return {
reCaptchaVerify: function (response) {
/** @param {string} response */
if (response === container.querySelector('.g-recaptcha-response').value) {
PubSub.publish('verify-response', {
successful: response
});
}
},
reCaptchaCallback: function () {
var parentEl;
container = $('[id*="reCaptcha20_"]', context)[0]; /* recaptcha ID must be unique. Prefix them with 'reCaptcha20_' */
if (container instanceof HTMLElement) {
id = container.id;
parentEl = container.parentElement;
parentEl.removeChild(container); /* prevents rendering duplicates */
parentEl.appendChild(container); /* prevents rendering duplicates */
clientId = grecaptcha.render(id, {
'sitekey': KEY, /* whatever your key is */
'callback': xReCaptchaVerify,
'expired-callback': xReCaptchaExpired
});
}
else {
throw new Error(container);
}
},
reCaptchaExpired: function () {
PubSub.publish('verify-response', {
successful: -1
});
},
globalize: function () {
/** Make it Global so google has access */
WIN.xReCaptchaCallback = this.reCaptchaCallback;
WIN.xReCaptchaVerify = this.reCaptchaVerify;
WIN.xReCaptchaExpired = this.reCaptchaExpired;
GetScript('', 'https://www.google.com/recaptcha/api.js?onload=xReCaptchaCallback&render=explicit');
}
};
};
/** Call function in your ajax **/
/* instead of $("#captcha_signin").show(); */
var captcha = new Captcha(this); /** @this {object} - $('#login_form') */
/** Verify the response **/
PubSub.subscribe('verify-response',function (name, response) {
/**
* listen for successful captcha response and proceed with submission
* @param {object} - response.successful should be a looooooong string
*/
if (typeof response.successful === 'string') {
/* Pass */
} else {
/* Fail */
throw new Error(response.successful + ' - should be a string');
}
});
关于jquery - recaptcha 2.0 - 如何仅在 n 次失败尝试/限制后显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30274985/
我在我的一种表单中集成了 reCAPTCHA v3。在 onload 中,右下角有一个生成的 token 和谷歌验证码标志。但是当我提交表单时,在控制台中会显示一个错误,“错误:不存在 reCAPTC
是我还是 recaptcha 图像无法翻译成除 EN 以外的其他语言? 我有 它仍然是英文的。这是故意的吗? 最佳答案 对于 reCAPTCHA 2. 一段时间过去了 这是你的cdn链接看最后,hl参
我正在尝试按照 https://developers.google.com/recaptcha/docs/faq#can-i-use-recaptcha-globally 中的说明在全局范围内使用 r
我们在我们的网站之一中集成了隐形 recaptcha。每当我们提交表单时,它就会自动提交。 我在一些谷歌小组中读到,在边缘浏览器上访问时我们会遇到挑战。但对我们来说,它是自动提交的。 测试隐形reca
我目前使用的是假的开发域而不是 localhost在我的本地机器上,因为我有多个要在本地管理的网站。 Google reCAPTCHA 无法识别我的域,并给我以下错误:ERROR: Invalid d
reCAPTCHA 需要公钥和私钥才能在网站中实现。它还需要 reCAPTCHA key ,具体取决于网站。这背后的原因是什么?公钥和私钥是否会影响 reCAPTCHA 中显示的文字?我知道我可以将公
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭13 年前。 Improve th
我目前使用隐形recaptcha,如果它认为用户是机器人,它会自动显示一个验证码。 现在有了 Recaptcha v3,我很难理解它应该如何使用。 它返回一个分数,但是如果分数很低,这可能表明用户是机
我希望,如果用户(或漫游器)重复做同样的事情,那么Recaptcha v3的得分会下降,但是事实并非如此。 这是从我的日志中摘录的内容,当我在正在构建的网站上登录时尝试使用不同的密码时,该日志是其中的
我有新的隐形 recaptcha 工作正常,但它把徽章放在左下角或右下角。您可以使用“data-badge='inline'”覆盖它,并将其拉入表单中。谷歌对如何实际移动它非常含糊。您无法隐藏它,因为
我的网站正在使用 Google reCAPTCHA 控件,但我听说它被阻止了 中国,反正我看到有人报告说将 API 更改为 https://www.recaptcha.net在中国工作? Anyone
我面临以下情况:当用户点击提交按钮时,应用会禁用该按钮。然后,当 ReCaptcha 的回调函数被调用时,我可以再次启用该按钮。但是如果用户关闭验证窗口我怎么知道然后再次启用我的按钮? 最佳答案 我在
在 reCAPTCHA v3 文档中,它说 reCAPTCHA works best when it has the most context about interactions with your
我正在尝试在我的网站上呈现 google reCaptcha。我去了google reCaptcha admin ,设置标签,并添加两个域:一个是localhost,另一个是mydomain.com。
我已登录我的 Google 帐户,并导航到 reCaptcha 设置页面。但它显示的只是创建新 reCaptcha 帐户的表单。 我想我曾经能够为我的不同域找到我以前的帐户设置,但现在似乎没有任何地方
ReCaptcha v3 将不再提供验证码,而是依靠浏览器指纹识别和谷歌可以获得的有关您的其他信息。 这是一个测试:https://recaptcha-demo.appspot.com/recaptc
google recaptcha 创建了一个没有可访问性属性的 textarea,例如 aria-label。这导致 recaptcha 无法通过 Siteimprove 进行可访问性扫描。 我已经尝
我正在我的一个网站上实现 reCAPTCHA,并且我已经成功实现了它。它工作正常。有时仅通过单击“我不是机器人”才能完成 reCAPTCHA,但有时它会显示图像网格以选择正确的图像并完成验证码。 我只
我已经在我的网站上实现了 reCaptcha,但每当我测试它时,我都会尝试 3-5 次才能成功。我认为我的用户不会喜欢这个。我注意到有些网站有诸如“2 + 2 是什么?”之类的问题。类似的东西同样有效
我在 Angular+Spring MVC 应用程序中使用 Google reCaptcha 进行用户登录。我想知道谷歌是否对其每天(或周/月/年)支持的点击次数有任何限制。 最佳答案 首先,我建议您
我是一名优秀的程序员,十分优秀!