사용자 이름과 암호를 모두 확인하는 다음 코드가 있지만 사용자 이름이나 암호가 유효한지 확인하도록 변경하려고합니다.사용자 이름을 확인하는 기능 변경 || 암호
두 개의 서로 다른 함수 checkUsername
과 checkPassword
을 함수로 생각하고 각 입력에 대해 두 개의 콜 백이 있습니다.
나는 제대로 된 트랙에 있는지 또는 컨트롤러와 모델이 어떻게 변경 될 수 있는지 알고 싶습니다.
모델 :
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에서 시작하지 마십시오. 따라서 코드를 다시 실행하고 있습니다. 당신은 방금 나에게 유효한 포인트를주었습니다 :) –