Welcome Guest, Not a member yet? Register   Sign In
Need Help! Bcrypt Issue Not Letting Me Login
#1

[eluser]riwakawd[/eluser]
I cannot seem to get the login function. Will not let me login with correct details. I use codeigniter bcrypt not having any luck hopeless.

Very strange No Errors.

Model

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_login_model extends CI_Model {

public function __construct() {
      parent::__construct();

      $this->load->library('bcrypt');
   }

   public function login($username, $hash) {
    $this->db->where('username', $username);

  $query = $this->db->get('user');

  if ($query->num_rows() == 1) {

   $user = $query->row();

   $password = $user->password;

   if ($this->bcrypt->check_password($password, $hash)) {
    
      return $query->row();
      return true;

     } else {

      $this->session->set_flashdata('error', 'Username Or Password Incorrect Please Try Again!');

      redirect('admin', 'refresh');

     }
  }  
}

public function logout() {
  $this->session->sess_destroy();
  redirect('admin');
}

}

Controller

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends MX_Controller {

public function __construct() {
  parent::__construct();
  $this->load->library('bcrypt');
  $this->lang->load('admin/common/login', 'english');
  $this->load->model('admin/common/user_login_model');
}

public function index() {

  $this->load->library('form_validation');

  $this->form_validation->set_rules('username', 'username', 'required|trim|min_length[2]|max_length[30]|xss_clean');
    $this->form_validation->set_rules('password', 'password', 'required|trim|min_length[3]|max_length[30]|xss_clean');

    $this->form_validation->set_message('required', 'This %s is Required');
    $this->form_validation->set_message('min_length', 'This %s must have at least %s characters');
    $this->form_validation->set_message('max_length', 'This %s must have at least %s characters');

    if ($this->form_validation->run() == FALSE) {

     $this->login();

    } else {

     $username = $this->input->post('username');
   $password = $this->input->post('password');

   $login = $this->user_login_model->login($username, $password);

   if ($login) {

    $data = array(
     'logged' => TRUE,
     'username' => $username
    );

    $this->session->set_userdata($data);

    redirect('admin/dashboard');
   }

    }

}

public function login() {
    $data['text_login'] = $this->lang->line('text_login');
  $data['text_register'] = $this->lang->line('text_register');

  $data['entry_username'] = $this->lang->line('entry_username');
    $data['entry_password'] = $this->lang->line('entry_password');

  $data['action'] = site_url('admin');

  $data['button_login'] = $this->lang->line('button_login');

  return $this->load->view('common/login', $data);
   }
  
}


#2

[eluser]riwakawd[/eluser]
I after having a look around on Google I was able to find a suitable auth library that meets my needs which is secure and better hashing. And modified some files.

I can login now it is similar to bcrypt hashing.




Theme © iAndrew 2016 - Forum software by © MyBB