私はユーザー名とパスワードの両方をチェックする次のコードを持っていますが、ユーザー名またはパスワードが有効かどうかをチェックするように変更したいと思います。ユーザー名を確認する関数の変更||パスワード
私は2つの異なる関数checkUsername
とcheckPassword
を関数として考えていて、各入力に対して2つのコールバックを持っていました。
私はちょうど私が正しいトラックにいるのか、コントローラとモデルがどのように変更できるのかを知りたいのですが?
モデル:
function check_login($username,$password) {
$query = $this->db->query("SELECT id, first_name, last_name, email, password FROM users WHERE email = ? and password = ?", array($username, md5($password))); // Result
return ($query->num_rows() == 1) ? $query->row() : FALSE;
}
}
コントローラー:
function _checkUsernamePassword() {
// adding the _ makes the function 'private' so it can't be called from the URI.
extract($_POST); // Gets data from form and creates vars
$user = $this->login_model->check_login($username,$password);
if(! $user){ // != If username or password are not correct
$this->session->set_flashdata('login_error',TRUE); //does not add the non valid login to the session
$this->form_validation->set_message('_checkUsernamePassword', 'Sorry %s is not correct.');
return FALSE;
} else {
$this->session->set_userdata('logged_in',TRUE);
$this->session->set_userdata('user_id',$user->id);
$this->session->set_userdata('user_name',$user->first_name);
$this->session->set_userdata('user_email',$user->email);
return TRUE;
}
私はMD5を使い始めません。なぜコードをやり直すのですか?あなたはちょうど私に有効なポイントを与えている:) –