Guest User

Untitled

a guest
May 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Jotorres Login Screen | Welcome </title>
  4. </head>
  5. <body>
  6. <div id='login_form'>
  7. <form action="<?php echo base_url();?>Login/process" method='post' name='process' enctype="multipart/form-data">
  8. <h2>User Login</h2>
  9. <br />
  10. <?php if(! is_null($msg)) echo $msg;?>
  11. <label for='username'>Username</label>
  12. <input type='text' name='username' id='username' size='25' /><br />
  13. <label for='password'>Password</label>
  14. <input type='password' name='password' id='password' size='25' /><br />
  15. <input type='Submit' value='Login' />
  16. </form>
  17. </div>
  18. </body>
  19. </html>
  20.  
  21. <?php
  22.  
  23. if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  24. /* Author: Jorge Torres
  25. * Description: Login controller class
  26. */
  27. {
  28. class Login extends CI_Controller{
  29.  
  30. function __construct(){
  31. parent::__construct();
  32. }
  33.  
  34.  
  35. public function index($msg = NULL){
  36. // Load our view to be displayed
  37. // to the user
  38. $data['msg'] = $msg;
  39. $this->load->view('login_view', $data);
  40. }
  41.  
  42.  
  43. public function process(){
  44. // Load the model
  45. $this->load->model('login_model');
  46. // Validate the user can login
  47. $result = $this->login_model->validate();
  48. // Now we verify the result
  49. if(! $result){
  50. // If user did not validate, then show them login page again
  51. $msg = '<font color=red>Invalid username and/or password.</font><br />';
  52. $this->index($msg);
  53. }else{
  54. // If user did validate,
  55. // Send them to members area
  56. redirect('Home');
  57. }
  58. }
  59. }
  60. }
  61. ?>
  62.  
  63. <?php
  64. defined('BASEPATH') OR exit('No direct script access allowed');
  65. /* Author: Jorge Torres
  66. * Description: Login model class
  67. */
  68. class Login_model extends CI_Model{
  69. function __construct(){
  70. parent::__construct();
  71. }
  72.  
  73. public function validate(){
  74. // grab user input
  75. $username = $this->security->xss_clean($this->input->post('username'));
  76. $password = $this->security->xss_clean($this->input->post('password'));
  77.  
  78. // Prep the query
  79. $this->db->where('username', $username);
  80. $this->db->where('password', $password);
  81.  
  82. // Run the query
  83. $query = $this->db->get('users');
  84. // Let's check if there are any results
  85. if($query->num_rows == 1)
  86. {
  87. // If there is a user, then create session data
  88. $row = $query->row();
  89. $data = array(
  90. 'userid' => $row->userid,
  91. 'fname' => $row->fname,
  92. 'lname' => $row->lname,
  93. 'username' => $row->username,
  94. 'validated' => true
  95. );
  96. $this->session->set_userdata($data);
  97. return true;
  98. }
  99. // If the previous process did not validate
  100. // then return false.
  101. return false;
  102. }
  103. }
  104. ?>
Add Comment
Please, Sign In to add comment