Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class VerifyLogin extends CI_Controller {
  4.  
  5. function __construct()
  6. {
  7. parent::__construct();
  8. $this->load->model('user','',TRUE);
  9. $this->load->helper('url');
  10. }
  11.  
  12. function index()
  13. {
  14. //This method will have the credentials validation
  15. $this->load->library('form_validation');
  16.  
  17. $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
  18. $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
  19.  
  20. if($this->form_validation->run() == FALSE)
  21. {
  22. //Field validation failed. User redirected to login page
  23. $this->load->view('login_view');
  24. }
  25. else
  26. {
  27. //Go to private area
  28. redirect('home', 'refresh');
  29. }
  30.  
  31. }
  32.  
  33. function check_database($password)
  34. {
  35. //Field validation succeeded. Validate against database
  36. $username = $this->input->post('username');
  37.  
  38. //query the database
  39. $result = $this->user->login($username, $password);
  40.  
  41. if($result)
  42. {
  43. $sess_array = array();
  44. foreach($result as $row)
  45. {
  46. $sess_array = array(
  47. 'id' => $row->id,
  48. 'username' => $row->username
  49. );
  50. $this->session->set_userdata('logged_in', $sess_array);
  51. }
  52. return TRUE;
  53. }
  54. else
  55. {
  56. $this->form_validation->set_message('check_database', 'Invalid username or password');
  57. return false;
  58. }
  59. }
  60. }
  61.  
  62. <html>
  63. <head>
  64. <title>OpediaLab</title>
  65. </head>
  66. <body>
  67. <h1></h1>
  68. <?php echo validation_errors(); ?>
  69. <?php echo form_open('verifylogin'); ?>
  70.  
  71. <link rel="stylesheet" type="text/css" href="<?=base_url()?>style.css"/>
  72. <label for="username">Username:</label>
  73. <input type="text" size="20" id="username" name="username"/>
  74. <br/>
  75. <label for="password">Password:</label>
  76. <input type="password" size="20" id="passowrd" name="password"/>
  77. <br/>
  78. <input type="submit" value="Login"/>
  79. </form>
  80. </body>
  81. </html>
  82.  
  83. body{
  84. background-image: url("C:/wamp/www/CI/application/views/immagini/Opedia_LAB.png");
  85. background-color: green;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement