Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function auth(){
- if($_POST){
- $this->load->library('form_validation');
- $this->form_validation->set_rules('username', 'Username', 'required|trim|xss_clean');
- $this->form_validation->set_rules('password', 'Password', 'required|trim|xss_clean');
- if($this->form_validation->run() == FALSE){
- redirect('');
- }
- $username = $this->input->post('username');
- $password = $this->encrypt->sha1($this->input->post('password'));
- $level = $this->input->post('level');
- $temp = $this->model->login("where username = '$username' and password = '$password'
- and level = '$level'")->result_array();
- if($temp != NULL){
- $data = array(
- 'id' => $temp[0]['id_user'],
- 'nama' => $temp[0]['nama'],
- 'username' => $temp[0]['username'],
- 'password' => $temp[0]['password'],
- 'level' => $temp[0]['level'],
- );
- $this->session->set_userdata('login',$data);
- if($data["level"] == "1"){
- redirect("admin/dashboard");
- }
- elseif($data["level"] == "3"){
- redirect("admin/dashboard");
- }
- else {
- echo "ERROR! 404 Tidak Ada";
- }
- }
- else {
- $error = '
- <div class="alert alert-danger alert-dismissable fade in">
- <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
- <strong>Kesalahan!</strong> Silahkan cek kembali username, password dan level anda.
- </div>
- ';
- $this->session->set_flashdata('error', $error);
- redirect('login');
- }
- }
- else {
- redirect('');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement