- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在构建一个带有暴力检查器的登录脚本,该检查器在被触发时会显示 reCAPTCHA。我遇到的问题是,当输入正确的用户名/密码/验证码响应时,登录脚本会运行,但直到大部分页面内容已加载(这发生在提交表单之后)。结果是我必须按 F5 键刷新页面并重新提交表单数据,以便在页面开始加载时 session 处于事件状态。
现在,我遇到的问题是,一旦表单被提交(当它需要一个验证码时), session 不会开始,直到 index.php 到达
else {
$captchaResponse = 1;
$auth = Auth::verifyPass($userName,$password,$captchaResponse);
}
我很困惑如何重新组织它,以便 session 在此之前开始。有什么想法吗?
第一部分是 index.php 页面,其中包含在检测到暴力破解尝试时触发的代码。这部分代码以条件 if($auth === "bruteForce") 开头 此代码显示 reCAPTCHA 并且应该将用户名、密码和 reCAPTCHA 响应代码(0-错误响应,1-正确响应)提交回登录功能。
<?php
include('includes/header.php');
spl_autoload_register(function ($class){
include 'includes/class.' . $class . '.php';
});
if(null !==(filter_input(INPUT_POST,'userName'))){$userName = filter_input(INPUT_POST,'userName');}
if(null !==(filter_input(INPUT_POST,'password'))){$password = filter_input(INPUT_POST,'password');}
if(isset($userName)&& isset($password)){
$auth = Auth::verifyPass($userName,$password);
}
if(isset($_GET['logout']) && $_GET['logout'] == true){
session_start();
session_destroy();
setcookie ("PHPSESSID", "", time() - 3600, "/");
header("Location: index.php");
}
if(Auth::checkLoggedIn() === true){
if(session_id() !== ''){echo 'Session ID is not blank<br />';}
echo '<a href="index.php?logout=true">Logout</a><br />';
echo 'Welcome! This is protected content!' . "<br />";
}
if(!Auth::checkLoggedIn()) :
?>
<h1>Sign In</h1>
<?php if(isset($userName) && isset($password)){if($auth === "invalidPassword"){echo '<span class="error">Invalid username or password</span>';}} ?>
<form name="login" method="post" action="index.php" id="loginForm">
<ul>
<li>
<input placeholder="Username" type="text" name="userName" id="userName" class="login" />
</li>
<li>
<input placeholder="Password" type="password" name="password" id="password" class="login" />
</li>
<?php
if(isset($userName) && isset($password)){
echo $auth . "<br />";
if($auth === "bruteForce"){
echo $auth;
require_once('includes/recaptchalib.php');
// Get a key from https://www.google.com/recaptcha/admin/create
$publickey = "xxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$privatekey = "xxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$resp = null;
$error = null;
if(isset($_POST["recaptcha_response_field"])){
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if ($resp->is_valid) {
Auth::checkLoggedIn();
$auth = Auth::verifyPass($userName,$password,1);
} else {
$auth = Auth::verifyPass($userName,$password,0);
//$captchaResponse = 2;
}
}
echo recaptcha_get_html($publickey, $error);
if($auth === "invalidCaptcha"){
echo "Invalid Captcha Response. Please try again.";
}
}
}
if(isset($auth)){echo $auth;}
?>
<div class="clearAll"> </div>
<li id="submit">
<input type="submit" value="Login" id="loginBtn" class="login" />
</li>
<li id="reset">
<input type="reset" value="Reset" id="resetBtn" class="login" />
</li>
</ul>
</form>
<div class="clearAll"> </div>
<h1>New User?</h1>
<p><a href="register.php">Sign Up!</a></p>
<?php endif; ?>
<div class="clearAll"> </div>
<?php include('includes/footer.php'); ?>
</body>
</html>
这是登录函数
public static function verifyPass($username,$password,$captchaResponse = 3){
$authenticatedUser = FALSE;
$bruteTest = self::_bruteTest($username);
if($bruteTest === TRUE && $captchaResponse === 3){
$status = "bruteForce";
return $status;
} else if($bruteTest === TRUE && $captchaResponse === 0){
//The brute force check was positive and the captcha response failed
//Don't even try to log in because the captcha failed.
$status = "invalidCaptcha";
return $status;
} else if ($bruteTest === TRUE && $captchaResponse === 1){
//The brute force check was positive and the captcha response was successful
//Try to log in now.
$continueLogin = TRUE;
} else if($bruteTest === FALSE){
//The bruteTest was negative, proceed with login.
$continueLogin = TRUE;
}
if($continueLogin === TRUE){
try{
$connection = Database::getDbConnection();
if($connection){
$query = "SELECT usr_name, usr_pass, usr_salt, uid, email_pri FROM users WHERE usr_name=? LIMIT 1";
$stmt = $connection->prepare($query);
$stmt->execute(array($username));
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
if($stmt->rowCount() === 0){$authenticatedUser = FALSE;} //Username was not found We are not going to say which was incorrect, only that the "username or password was incorrect"
if($results){
$resultsArray = $results[0];
$connection = null;
echo "<br />";
$dbUserName = $resultsArray['usr_name'];
$dbPass = $resultsArray['usr_pass'];
$dbSalt = $resultsArray['usr_salt'];
$dbUid = $resultsArray['uid'];
$dbEmail = $resultsArray['email_pri'];
$passHash = hash('sha512',$password);
$passToCheck = hash('sha512',$dbSalt.$passHash);
if($passToCheck != $dbPass){
$authenticatedUser = FALSE; //Password did not match. We are not going to say which was incorrect, only that the "username or password was incorrect"
} else if ($passToCheck === $dbPass && $username === $dbUserName){
$authenticatedUser = TRUE;
}
}
}else if(!$results){$authenticatedUser = FALSE;}
} catch (PDOException $e) {
echo "Error: " . $e->getMessage() . "<br />";
die();
}
try{
if($authenticatedUser === FALSE){
//Log the failed attempt into the database
$remoteIp = $_SERVER['REMOTE_ADDR'];
try {
$connection = Database::getDbConnection();
if($connection){
$query = "INSERT INTO `login_attempts`(`usr_name`, `usr_ip`) VALUES (:usr_name,INET_ATON(:usr_ip))";
$stmt = $connection->prepare($query);
$stmt->execute(array(':usr_name' => $username, ':usr_ip' => $remoteIp));
}
$connection = null;
} catch (PDOException $e){
echo "Error: " . $e->getMessage() . "<br />";
die();
}
$status = "invalidPassword";
return $status;
exit();
}else if($authenticatedUser === TRUE){
//Clear login attempts from the database
self::_clearAttempts($username);
//Start the session (if not already started somehow. session and cookie expiration need to be adjusted so that the session does not persist after browser close)
if(!isset($_SESSION)){
session_start();
}
//Set the session variables
$_SESSION['userIp'] = $_SERVER['REMOTE_ADDR'];
$_SESSION['userName'] = $dbUserName;
$_SESSION['userAgent'] = $_SERVER['HTTP_USER_AGENT'];
$session_name = 'sec_session_id';
$httponly = TRUE;
$cookieParams = session_get_cookie_params();
session_set_cookie_params($cookieParams["lifetime"],
$cookieParams["path"],
$cookieParams["domain"],
$httponly);
session_name($session_name);
}
} catch (PDOException $e) {
echo "Error: " . $e->getMessage() . "<br />";
die();
}
//End $continueLogin statement below
}
}
最佳答案
移动这个:
if(!isset($_SESSION)){
session_start();
}
到脚本的顶部并尝试。
或者只是:
session_start();
关于如果检测到暴力尝试,PHP 使用 reCAPTCHA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22025880/
我在我的一种表单中集成了 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 进行用户登录。我想知道谷歌是否对其每天(或周/月/年)支持的点击次数有任何限制。 最佳答案 首先,我建议您
我是一名优秀的程序员,十分优秀!