代码点火器;在第 n 次失败尝试后禁用登录
CodeIgniter; disable login after nth unsuccessful attempts
我想尝试一项功能,将用户不成功的登录尝试次数限制在 5 次,然后向他们发送一条消息。
下面是我的代码:
$attempts = $this->input->post('attempts');
if ($attempts <= '5')
{
$this->db->where('username', $username);
$this->db->set('attempts', '`attempts`+ 1', FALSE);
$this->db->update('tb_user');
}
else
{
echo "Your account is locked!";
}
以上代码可以更新数据库 table 和列尝试,但记录在 5 次尝试后仍在更新,如:存储第 6 次、第 7 次和第 n 次不成功的登录尝试。
我做错了什么,我该如何解决?
从数据库获取尝试计数,而不是从前端传递。
$attempts = $this->db->where('username', $username)->get('tb_user')->row()->attempts;
if ($attempts > 4)
{
echo "Your account is locked!";
}
else
{
$this->db->where('username', $username);
$this->db->set('attempts', ($attempts + 1), FALSE);
$this->db->update('tb_user');
}
我想尝试一项功能,将用户不成功的登录尝试次数限制在 5 次,然后向他们发送一条消息。
下面是我的代码:
$attempts = $this->input->post('attempts');
if ($attempts <= '5')
{
$this->db->where('username', $username);
$this->db->set('attempts', '`attempts`+ 1', FALSE);
$this->db->update('tb_user');
}
else
{
echo "Your account is locked!";
}
以上代码可以更新数据库 table 和列尝试,但记录在 5 次尝试后仍在更新,如:存储第 6 次、第 7 次和第 n 次不成功的登录尝试。
我做错了什么,我该如何解决?
从数据库获取尝试计数,而不是从前端传递。
$attempts = $this->db->where('username', $username)->get('tb_user')->row()->attempts;
if ($attempts > 4)
{
echo "Your account is locked!";
}
else
{
$this->db->where('username', $username);
$this->db->set('attempts', ($attempts + 1), FALSE);
$this->db->update('tb_user');
}