Guest User

Untitled

a guest
Nov 13th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. <body>
  2. <h1>LOG IN!</h1>
  3. <form action="" method="post">
  4. <label for="username">Username:</label>
  5. <input type="text" id="username" name="username" >
  6. <label for="password">Password</label>
  7. <input type="password" id="password" name="password" >
  8. <br>
  9. <button id="btn_login" name="btn_login" >LOG IN!</button>
  10. </form>
  11. <div class="errors" ><?php echo validation_errors(); ?></div>
  12. </body>
  13.  
  14. <?php
  15. class User_model extends CI_Model {
  16. public $m_sUsername;
  17. public $m_sPassword;
  18. public $m_sEmail;
  19. public $m_sPicture;
  20.  
  21. function __construct()
  22. {
  23. parent::__construct();
  24. }
  25.  
  26. function get_user($username, $password)
  27. {
  28. $this->db->select("username","password");
  29. $this->db->from(user);
  30. $this->db->where('username',$username);
  31. $this->db->where('password',$password);
  32. $this->db->limit(1);
  33. $query = $this->db->get();
  34. return $query->num_rows();
  35. }
  36. }
  37.  
  38. <?php
  39.  
  40. class Login extends CI_Controller {
  41.  
  42. function __construct()
  43. {
  44. parent::__construct();
  45. $this->load->library('session');
  46. $this->load->helper('form');
  47. $this->load->helper('url');
  48. $this->load->helper('html');
  49. $this->load->database();
  50. $this->load->library('form_validation');
  51. $this->load->model("User_model", "", true);
  52. }
  53.  
  54. public function index()
  55. {
  56. if ($this->input->server('REQUEST_METHOD') == 'POST') {
  57. $username = $this->input->post("username");
  58. $password = $this->input->post("password");
  59. $this->form_validation->set_rules("username", "Username", "trim|required");
  60. $this->form_validation->set_rules("password", "Password", "trim|required");
  61.  
  62. if ($this->form_validation->run() == FALSE) {
  63. //validation fails
  64. echo "Vul alle velden in";
  65. } else {
  66. //validation succeeds
  67. if ($this->input->post('btn_login') == "Login") {
  68. //check if username and password is correct
  69. $usr_result = $this->User_model->get_user($username, $password);
  70. if ($usr_result > 0) { //active user record is present
  71. echo 'Ingelogd!';
  72. } else {
  73. echo "Wrong!";
  74. }
  75. }
  76. }
  77. }
  78.  
  79. $this->load->view("admin/login_view.php");
  80. }
  81. }
  82.  
  83. $config['csrf_protection'] = TRUE;
  84.  
  85. <input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">
  86.  
  87. public function index()
  88. {
  89. // Load Login Page
  90. redirect('login/login_page','refresh');
  91.  
  92. }
  93.  
  94. public function login_page()
  95. {
  96. $data['title'] = 'Login Page';
  97.  
  98. $this->load->view('templates/header', $data);
  99. $this->load->view('users/login_view', $data);
  100. $this->load->view('templates/footer');
  101. }
Add Comment
Please, Sign In to add comment