Skip to Content
PHPCODE
CodeIgniter Verify Username Password
codeigniter code / July 29, 2018

Verify Username and password in codeigniter

step 1 : go to config file and autoload this($autoload[‘libraries’] = array();) write $autoload[‘libraries’] = array(‘database’);

step 2 : model code write
<?php
class Loginmodel extends CI_Model
{
public function login_valid($username,$password)
{
$q=$this->db->where([‘uname’=>$username,’pword’=>$password])
->get(‘users’);
if($q->num_rows())
{
return TRUE;
}
else
{
return FALSE;
}
}
}
?>

Step 3 :- Create Controller this here
for Example
<?php
class Login extends MY_Controller
{
public function index()
{
$this->load->helper(‘form’);
$this->load->view(‘public/admin_login’);
}
public function admin_login()
{
$this->load->library(‘form_validation’);
$this->form_validation->set_rules(‘username’,’User Name’,’required|trim|alpha’);
$this->form_validation->set_rules(‘password’,’Password’,’required’);
$this->form_validation->set_error_delimiters(“<p class=’text-danger’>”,”</p>”);
if($this->form_validation->run()==TRUE)
{

$username=$this->input->post(‘username’);
$password=$this->input->post(‘password’);
$this->load->model(‘loginmodel’);
if($this->loginmodel->login_valid($username,$password))
{
echo “password match”;
//credetials valid login user
}
else
{
echo “password no not match”;
//authentication fail
}
}
else
{
$this->load->view(‘public/admin_login’);
//echo validation_errors();
}
}
}
?>

Comments
No comments yet, take the initiative.

Leave a Reply

Your email address will not be published.

PHPCODE © 2023