Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>Jotorres Login Screen | Welcome </title>
- </head>
- <body>
- <div id='login_form'>
- <form action="<?php echo base_url();?>Login/process" method='post' name='process' enctype="multipart/form-data">
- <h2>User Login</h2>
- <br />
- <?php if(! is_null($msg)) echo $msg;?>
- <label for='username'>Username</label>
- <input type='text' name='username' id='username' size='25' /><br />
- <label for='password'>Password</label>
- <input type='password' name='password' id='password' size='25' /><br />
- <input type='Submit' value='Login' />
- </form>
- </div>
- </body>
- </html>
- <?php
- if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- /* Author: Jorge Torres
- * Description: Login controller class
- */
- {
- class Login extends CI_Controller{
- function __construct(){
- parent::__construct();
- }
- public function index($msg = NULL){
- // Load our view to be displayed
- // to the user
- $data['msg'] = $msg;
- $this->load->view('login_view', $data);
- }
- public function process(){
- // Load the model
- $this->load->model('login_model');
- // Validate the user can login
- $result = $this->login_model->validate();
- // Now we verify the result
- if(! $result){
- // If user did not validate, then show them login page again
- $msg = '<font color=red>Invalid username and/or password.</font><br />';
- $this->index($msg);
- }else{
- // If user did validate,
- // Send them to members area
- redirect('Home');
- }
- }
- }
- }
- ?>
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- /* Author: Jorge Torres
- * Description: Login model class
- */
- class Login_model extends CI_Model{
- function __construct(){
- parent::__construct();
- }
- public function validate(){
- // grab user input
- $username = $this->security->xss_clean($this->input->post('username'));
- $password = $this->security->xss_clean($this->input->post('password'));
- // Prep the query
- $this->db->where('username', $username);
- $this->db->where('password', $password);
- // Run the query
- $query = $this->db->get('users');
- // Let's check if there are any results
- if($query->num_rows == 1)
- {
- // If there is a user, then create session data
- $row = $query->row();
- $data = array(
- 'userid' => $row->userid,
- 'fname' => $row->fname,
- 'lname' => $row->lname,
- 'username' => $row->username,
- 'validated' => true
- );
- $this->session->set_userdata($data);
- return true;
- }
- // If the previous process did not validate
- // then return false.
- return false;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment