Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <link rel="stylesheet" type="text/css" href="bootstrap/dist/css/bootstrap.css">
- </head>
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Auth extends CI_Controller {
- public function index(){
- if (! $this->session->has_userdata('username')) {
- redirect('auth/login');
- }
- echo password_hash('admin', PASSWORD_DEFAULT);
- $this->load->view('auth/login');
- }
- public function login(){
- $args = array(
- 'error' => $this->session->flashdata('error')
- );
- $this->load->view('auth/login',$args);
- }
- public function proses_login(){
- /* membuat input*/
- $username = $this->input->post('username');
- $password = $this->input->post('password');
- /*
- *cek apakah button telah diklik atau belum
- *bila belum maka akan diredirect ke halaman login
- */
- if (empty($this->input->post('login'))) {
- redirect('/');
- return;
- }
- $this->load->model('usermodel');
- $users = $this->usermodel
- ->getUserByUsername($username)
- ->result();
- if (empty($users[0])) {
- $this->session->set_flashdata(
- 'error',
- 'username salah'
- );
- redirect('auth/login');
- return;
- }
- if( ! password_verify($password, $users[0]->password)){
- $this->session->set_flashdata(
- 'error',
- 'password salah'
- );
- redirect('auth/login');
- return;
- }
- $this->session->set_userdata('username', $username);
- redirect('/');
- return;
- }
- }
- ?>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement