我有一个基本的登录页面。该页面将用于记录登录失败的用户名和 unix 时间。
是否可以在允许用户输入密码之前查看用户名,如果尝试次数为 5 次或以上,则可以将其禁用 30 分钟。
我已经在网上搜索过,但找不到任何东西,另一个解决方案是在允许代码继续之前查看表格,但再次有一点大脑冻结,确定它很容易,但更愿意阻止用户早点?
我附上了检查页面,以便您可以看到我正在尝试的内容。
Include("include/conn.php");
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
mysqli_select_db('DATABASE');
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
// encrypt password
$encrypted_mypassword=md5($mypassword);
//see if account is locked
//STUCK HERE if looking at amount of attements before allowing code to run.
//look up username and pasword match
$sqli="SELECT * FROM TABLE WHERE Username='$myusername' and Password='$encrypted_mypassword'";
$result=mysql_query($sqli);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $Unique_Id and redirect to file "home.php"
session_register("myusername");
session_register("Unique_Id");
header("location:home.php");
}
//if log in if not sucsesfull
else {
echo "Wrong Username or Password";
//update attempt log with attempt +1 and unix time
$sql_query_update = "UPDATE TABLE SET
Attempts = Attempts+1,time = UNIX_TIMESTAMP(now())
WHERE TABLE.Username ='$myusername'";
mysql_query( $sql_query_update );
//close mysql
mysql_Close();
}
?>
我知道过时的代码,但这仅用于测试,因为我正在努力mysqli
在我的虚拟服务器上进行配置。