我想要做的是弄清楚如何設置新的密碼和它的請求日期(0000-00-00 00:00:00),然後根據它發送電子郵件。然而,我想我需要改變我的邏輯,因爲如果它已經設置,我不想讓它保持大量發送電子郵件的用戶。另外我不確定的是如果他們沒有收到郵件。忘記密碼邏輯
關於我該怎麼做的任何想法?
編輯:只是想補充說,new_password_key不是用戶登錄的密碼。截至目前,我打算讓他們通過電子郵件中的鏈接指向一個頁面,以便他們輸入新密碼。
if (!isset($user_data->new_password_key) && (!isset($user_data->new_password_requested)))
{
if ($this->kow_auth->forgot_password($this->input->post('username')))
{
$this->kow_auth->send_email('forgot_password', 'KOW Manager Forgot Password Email', $user_data);
echo json_encode(array('success' => 'yes', 'message' => 'A temporary password has been emailed to you!'));
}
else
{
}
}
else
{
echo json_encode(array('success' => 'yes', 'message' => 'Check your email for your temporary password!'));
}
編輯2:
那裏只是似乎有些邏輯問題,我與它,因爲如果它下來if語句如果($ already_sent_password)出於某種原因,他們沒」沒有得到它。那又怎麼樣?或者如果它下降到if(!strtotime($ user_data-> new_password_requested)< =(time() - 172800)),這對我來說聽起來很愚蠢,因爲爲什麼他們不得不等待兩天才能獲得新密碼鍵。
function forgot_password_submit()
{
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
if (!$this->form_validation->run())
{
echo json_encode(array('error' => 'yes', 'message' => 'There was a problem submitting the form! Please refresh the window and try again!'));
return;
}
$user_data = $this->users->get_user_by_username($this->input->post('username'));
if ($user_data === NULL)
{
echo json_encode(array('error' => 'yes', 'message' => 'User does not exist in the database!'));
return;
}
$already_sent_password = (isset($user_data->new_password_key) && isset($user_data->new_password_requested));
if ($already_sent_password)
{
echo json_encode(array('success' => 'yes', 'message' => 'Check your email for your temporary password!'));
return;
}
if (!strtotime($user_data->new_password_requested) <= (time() - 172800))
{
echo json_encode(array('error' => 'yes', 'message' => 'You have to wait 2 days before a new temp password can be emailed!'));
}
else
{
if ($this->kow_auth->forgot_password($this->input->post('username')))
{
$this->kow_auth->send_email('forgot_password', 'KOW Manager Forgot Password Email', $user_data);
echo json_encode(array('error' => 'yes', 'message' => 'A temporary password has been emailed to you'));
}
else
{
echo json_encode(array('error' => 'yes', 'message' => 'A temporary password could not be created for you!'));
}
}
是的,但其他人可以點擊該按鈕太。或者機器人。 – bottleboot 2012-02-15 20:17:34
這就是我所擔心的。 – 2012-02-15 20:19:36
我還在codereview頁面上發佈了一篇關於我的整個提交功能的文章,以便讓大家認爲。 http://codereview.stackexchange.com/questions/9010/forgotten-password-logic不確定關於它的邏輯。 – 2012-02-15 20:20:27