Codeigniter Tutorials
- What is codeigniter?
- Application_Architecture
- MVC Architecture
- HMVC Architecture
- Codeigniter Configuration
- Remove index.php from url in codeigniter
- MVC Concept
- View
- Alternate PHP Syntax for View Files
- Routing
- Codeigniter URL
- Get Current URL
- Previous page URL get
- Seo Friendly URL
- Slug Create in codeigniter
- What is _remap() function
- Remove controller name from url in codeigniter
- Codeigniter Controller Class
- Class Constructor
- GET $ POST method in Codeigniter
- Models
- Basepath, Apppath, FCPATH
- URI Segment
- Page Redirect
- Helper class
- Custom Helper class
- Form Helper
- Common Helper Functions
- Common Function
- Array Problems
- Call controller in Helper
- Add active class to menu using Helper class
- Custom Library
- Custom Library Example
- when to use get_instance()
- Codeigniter Hook
- how to work inline css in codeigniter
- Custom 404 page
- 404 custom error page
- Create custom config file in codeigniter
- How to set and get config item value
- How to Speed Up CodeIgniter App?
- Codeigniter Functions
- Session
- cookies
- How to Set & Get Tempdata in Codeigniter
- flash messages in Codeigniter
- Flashdata
- Encryption and Decryption In CodeIgniter
- Codeigniter security
- csrf token form security
- Password Hashing
- Form Validation
- Custom Validation
- Registration Form with validation
- Server Side Form Validation
- Validate Select Option Field
- Date Format Validation
- Date Format change in codeigniter
- Date Functions
- DOB Validation
- CI CRUD
- User SignUp
- User Login
- User Logout
- Login Account
- Login form with RememberMe
- Login Form with session
- User change password
- Change Password with Callback Validation to Check Old Password
- Forgot password
- Reset password
- Insert data in database
- Fetch data from database
- Update data in database
- Delete data in database
- File Upload
- Image Upload with resize Image
- Upload Multiple file and images
- Upload Multiple images with CRUD
- File and image update
- Upload Image Using Ajax.
- Email Send
- Email Send Using Email library
- Email Send Using SMTP Gmail
- Notification send
- store data in json format in DB
- Json parse
- Fetch data Using Ajax with Json data
- How to Show data Using Ajax with Json parse
- Get JSON Data from PHP Script using jQuery Ajax
- Insert data Using Ajax
- Submit data Using Ajax with form validation
- How to show data Using Ajax in codeigniter
- Insert & Update Using Ajax
- Registration Form With Validation Using Ajax in codeigniter
- Delete data Using Ajax Confirmation
- Delete All data Using checkbox selection
- Ajax CSRF Token
- Ajax Post
- Ajax serverside form validation
- Contact form using AJAX with form validation
- DataTable Using Ajax dynamically
- DataTables pagination using AJAX with Custom filter
- DataTables AJAX Pagination with Search and Sort in codeigniter
- DataTables in Codeigniter using Ajax
- Ajax Custom Serarch
- Ajax Live Data Search using Jquery PHP MySql
- Ajax Custom Serarch and sorting in datatable
- Dynamic Search Using Ajax
- Autocomplete using jquery ajax
- Jquery Ajax Autocomplete Search using Typeahead
- Dynamic Dependent Dropdown Using Ajax
- Dynamic Dependent Dropdown list Using Ajax
- Dynamic Dependent Dropdown in codeigniter using Ajax
- ajax username/email availability check using JQuery
- Check Email Availability Using Ajax
- Data Load on mouse scroll
- Ajax CI Pagination
- Pagination in codeigniter
- Ajax Codeigniter Pagination
- email exists or not using ajax with json
- CRUD using AJAX With Modal popup in CI
- Add / Show Data on modal popup using Ajax
- Modal popup Validation using Ajax
- Data show on Modal popup Using Ajax
- Add / Remove text field dynamically using jquery ajax
- How to Add/Delete Multiple HTML Rows using JavaScript
- Delete Multiple Rows using Checkbox
- Multiple Checkbox value
- Form submit using jquery Example
- REST & SOAP API
- Multi-Language implementation in CodeIgniter
- How to pass multiple array in view
- Captcha
- create zip file and download
- PhpOffice PhpSpreadsheet Library (Export data in excel sheet)
- data export in excel sheet
- Excel File generate in Codeigniter using PHPExcel
- Dompdf library
- tcpdf library
- Html table to Excel & docs download
- CI Database Query
- Database Query
- SQL Injection Prevention
- Auth Model
- Join Mysql
- Tree View in dropdown option list
- OTP Integration in codeigniter
- curl post
- download file using curl
- Sweet Alert
- Sweet alert Delete & Success
- Log Message in Codeigniter
- Menu & Submenu show dynamically
- Set Default value in input box
- Cron Jobs
- Stored Procedure
- Display Loading Image when AJAX call is in Progress
- Send SMS
- IP Address
- Codeigniter Tutorialspoint
- Website Link
- How To Create Dynamic Xml Sitemap In Codeigniter
- Paypal Payment Integration
- Get Latitude and Longitude From Address in Codeigniter Using google map API
- How To Create Simple Bar Chart In Codeigniter Using AmCharts?
- dynamic Highcharts in Codeigniter
- Barcode in Codeigniter
- Codeigniter Interview Questions
- Project
Home » Codeigniter »
User Change Password
Password_Change.php
<?php
class Password_Change extends CI_Controller
{
public function __construct()
{
//call CodeIgniter's default Constructor
parent::__construct();
//load database libray manually
$this->load->database();
$this->load->library('session');
//load Model
$this->load->helper('url');
$this->load->model('Form_model');
}
public function change_pass()
{
if($this->input->post('change_pass'))
{
$old_pass=$this->input->post('old_pass');
$new_pass=$this->input->post('new_pass');
$confirm_pass=$this->input->post('confirm_pass');
$session_id=$this->session->userdata('id');
$que=$this->db->query("select * from user_login where id='$session_id'");
$row=$que->row();
if((!strcmp($old_pass, $pass))&& (!strcmp($new_pass, $confirm_pass))){
$this->Form_model->change_pass($session_id,$new_pass);
echo "Password changed successfully !";
}
else{
echo "Invalid";
}
}
$this->load->view('change_pass');
}
}
?>
Form_model.php
<?php
class Form_model extends CI_Model
{
function fetch_pass($session_id)
{ $fetch_pass=$this->db->query("select * from user_login where id='$session_id'");
$res=$fetch_pass->result();
}
function change_pass($session_id,$new_pass)
{
$update_pass=$this->db->query("UPDATE user_login set pass='$new_pass' where id='$session_id'");
}
}
View :-
<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro|Open+Sans+Condensed:300|Raleway' rel='stylesheet' type='text/css'>
</head>
<body>
<div id="main">
<div id="login">
<?php echo @$error; ?>
<h2>Change Password</h2>
<br>
<form method="post" action=''>
<label>Old Password :</label>
<input type="password" name="old_pass" id="name" placeholder="Old Pass"/><br /><br />
<label>New Password :</label>
<input type="password" name="new_pass" id="password" placeholder="New Password"/><br/><br />
<label>Confirm Password :</label>
<input type="password" name="confirm_pass" id="password" placeholder="Confirm Password"/><br/><br />
<input type="submit" value="login" name="change_pass"/><br />
</form>
</div>
</div>
</body>
</html>
How to change user password :-
File Name : login-forget.php
<div class="container">
<form class="form-horizontal well" method="post" id="form" action="<?php echo base_url()?>login/doforget">
<fieldset>
<legend>Reset password</legend>
<div class="control-group">
<label for="email"> Email</label>
<input class="box" type="text" id="email" name="email" />
</div>
<div class="form-actions">
<input type="submit" class="btn btn-primary" value="Reset" />
</div>
<?php if( isset($info)): ?>
<div class="alert alert-success">
<?php echo($info) ?>
</div>
<?php elseif( isset($error)): ?>
<div class="alert alert-error">
<?php echo($error) ?>
</div>
<?php endif; ?>
</fieldset>
</form>
</div>
Controller
File Name : Login.php
<?php
defined('BASEPATH') OR exit('no direct script access allowed');
class Login extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('login');
}
public function doforget()
{
$this->load->helper('url');
$email= $_POST['email'];
$q = $this->db->query("select * from users where email='" . $email . "'");
if ($q->num_rows > 0) {
$r = $q->result();
$user=$r[0];
$this->resetpassword($user);
$info= "Password has been reset and has been sent to email id: ". $email;
redirect('login/forget?info=' . $info, 'refresh');
}
$error= "The email id you entered not found on our database ";
redirect('login/forget?error=' . $error, 'refresh');
}
private function resetpassword($user)
{
date_default_timezone_set('GMT');
$this->load->helper('string');
$password= random_string('alnum', 16);
$this->db->where('id', $user->id);
$this->db->update('users',array('password'=>MD5($password)));
$this->load->library('email');
$this->email->from('info@itechxpert.in', 'Your name');
$this->email->to($user->email);
$this->email->subject('Password reset');
$this->email->message('You have requested the new password, Here is you new password:'. $password);
$this->email->send();
}
public function forget()
{
if (isset($_GET['info'])) {
$data['info'] = $_GET['info'];
}
if (isset($_GET['error'])) {
$data['error'] = $_GET['error'];
}
$this->load->view('login-forget',$data);
}
}
Configure to send email.
File Name :
Inside the config folder(under application folder) create one config file called email.config. Codeigniter loads the configuration automatically while sending email.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*$config['protocol'] = 'sendmail';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
*/
$config['protocol'] = 'smtp';
$config['smtp_host']='ssl://smtp.mailgun.org';
$config['smtp_user']='mahtab.habi@gmail.com';
$config['smtp_pass']='youpassword';
$config['smtp_port']='465';
/* End of file config.php */
/* Location: ./application/config/config.php */
File Name :
File Name :
File Name :