Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. <html>
  2. <head>
  3. <link rel="stylesheet" type="text/css" href="bootstrap/dist/css/bootstrap.css">
  4. </head>
  5. <?php
  6. defined('BASEPATH') OR exit('No direct script access allowed');
  7.  
  8. class Auth extends CI_Controller {
  9. public function index(){
  10. if (! $this->session->has_userdata('username')) {
  11. redirect('auth/login');
  12. }
  13. echo password_hash('admin', PASSWORD_DEFAULT);
  14. $this->load->view('auth/login');
  15. }
  16.  
  17. public function login(){
  18. $args = array(
  19. 'error' => $this->session->flashdata('error')
  20. );
  21. $this->load->view('auth/login',$args);
  22. }
  23.  
  24. public function proses_login(){
  25. /* membuat input*/
  26. $username = $this->input->post('username');
  27. $password = $this->input->post('password');
  28.  
  29. /*
  30. *cek apakah button telah diklik atau belum
  31. *bila belum maka akan diredirect ke halaman login
  32. */
  33. if (empty($this->input->post('login'))) {
  34. redirect('/');
  35. return;
  36. }
  37. $this->load->model('usermodel');
  38. $users = $this->usermodel
  39. ->getUserByUsername($username)
  40. ->result();
  41.  
  42. if (empty($users[0])) {
  43. $this->session->set_flashdata(
  44. 'error',
  45. 'username salah'
  46. );
  47. redirect('auth/login');
  48. return;
  49. }
  50.  
  51. if( ! password_verify($password, $users[0]->password)){
  52. $this->session->set_flashdata(
  53. 'error',
  54. 'password salah'
  55. );
  56. redirect('auth/login');
  57. return;
  58. }
  59. $this->session->set_userdata('username', $username);
  60. redirect('/');
  61. return;
  62. }
  63. }
  64. ?>
  65. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement