* @see https://codeigniter.com/user_guide/general/urls.html */ public function __construct() { parent::__construct(); $this->load->library('form_validation'); } public function index() { $data['nama'] = "Login"; $this->form_validation->set_rules('username', 'Username', 'required|trim'); $this->form_validation->set_rules('password', 'Password', 'required|trim'); if ($this->form_validation->run() == false) { $this->load->view('Auth/index.php', $data); }else{ $this->_login(); } } public function _login(){ $username = $this->input->post('username'); $password = $this->input->post('password'); $user = $this->db->get_where('m_user', ['username' => $username])->row_array(); if ($user) { if (password_verify($password, $user['password'])) { $data = [ 'username' => $user['username'], 'id_user' => $user['id_user'] ]; $this->session->set_userdata($data); redirect('home'); } else { // jika password salaha $this->session->set_flashdata('flash', 'Salah'); $this->session->set_flashdata('data', 'Password'); $this->session->set_flashdata('message', ''); redirect('auth'); } } else { $this->session->set_flashdata('message', ''); $this->session->set_flashdata('flash', 'Terdaftar'); $this->session->set_flashdata('data', 'Username Anda Belum'); redirect('auth'); } } public function registration() { $this->form_validation->set_rules('username', 'Username', 'required|trim'); $this->form_validation->set_rules('email', 'Email', 'required|trim'); //rules ngecek email uniq $this->form_validation->set_rules( 'password', 'Password', 'required|trim|min_length[3]', [ 'min_length' => 'Password is too short' ] ); $this->form_validation->set_rules( 'con_password', 'Confirmation Password', 'required|matches[password]', [ 'matches' => 'The confirmation password does not match the password' ] ); $data['nama'] = "Registrasi"; if ($this->form_validation->run() == false) { $this->load->view('Auth/auth-register', $data); } else { $data = [ 'id_user' => '', 'email' => htmlspecialchars($this->input->post('email', true)), 'username' => htmlspecialchars($this->input->post('username', true)), 'password' => password_hash($this->input->post('password'), PASSWORD_DEFAULT) ]; $this->db->insert('m_user', $data); //kasi pesan $this->session->set_flashdata('message', '