Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
    • Guest Posting Service
  • Advertise
  • About
  • Contact Us

How to change password in CodeIgniter framework?

December 10, 2020 Pakainfo php, Codeigniter Leave a comment

Today, We want to share with you forgot password in codeigniter.In this post we will show you forgot password using otp in php, hear for codeigniter login and registration with forgot password we will give you demo and example for implement.In this post, we will learn about PHP Change Password Script Using Mysqli with an example.

forgot password with generated code in codeigniter

Contents

  • forgot password with generated code in codeigniter
    • Forms.php (Controller)
    • forgot_pass.php (View)
    • Forgot password with generated code in CodeIgniter
    • Html view
    • This controller function
    • This model function
    • Related posts

Forms.php (Controller)

<?php 
class Forms 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('Hello_model');
	}
	
   public function forgot_pass()
	{
		if($this->input->post('forgot_pass'))
		{
			$email=$this->input->post('email');
			$que=$this->db->query("select pass,email from member_login where email='$email'");
			$row=$que->row();
			$member_email=$row->email;
			if((!strcmp($email, $member_email))){
			$pass=$row->pass;
				/*Mail Code*/
				$to = $member_email;
				$subject = "Password";
				$txt = "Your password is $pass .";
				$headers = "From: [email protected]" . "\r\n" .
				"CC: [email protected]";

				mail($to,$subject,$txt,$headers);
				}
			else{
			$data['error']="
Invalid Email ID !
";
			}
		
	}
	   $this->load->view('forgot_pass',@$data);	
   }


	            
}
?>

forgot_pass.php (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>Forgot Password</h2>
<br>
<form method="post" action=''>
		<label>Email ID :</label>
		<input type="password" name="email" id="name" placeholder="Email ID"/><br /><br />
	    <input type="submit" value="login" name="forgot_pass"/><br />
</form>
</div>
</div>
</body>
</html>

Run the program on your browser with URL:

http://localhost/codeIgniter/index.php/Crud/storememberinfo

Forgot password with generated code in CodeIgniter

<form id="resetPassword" name="resetPassword" method="post" action="<?php echo base_url();?>My_Controller/ForgotPassword" onsubmit ='return validate()'>
                    <table class="table table-bordered table-hover table-striped">
                        <tbody>
                        <tr>
                            <td>Enter Email: </td>
                            <td>
                                <input type="email" name="email" id="email" style="width:250px" required>
                            </td>
                            <td><input type = "submit" value="submit" class="button"></td>
                        </tr>

                        </tbody>               </table></form>

Html view

public function ForgotPassword()
{
    $email = $this->input->post('email');
    $findemail = $this->MY_model->ForgotPassword($email);
    if ($findemail) {
        $this->MY_model->sendpassword($findemail);
    } else {
        echo "<script>alert(' $email not found, please enter correct email id')</script>";
        redirect(base_url() . 'MY_controller/index', 'refresh');
    }
}

This controller function

public function ForgotPassword($email)
{
    $this->db->select('email');
    $this->db->from('table');
    $this->db->where('email', $email);
    $query=$this->db->get();
    return $query->row_array();
}

This model function

public function sendpassword($data)
{
    $email = $data['email'];
    $query1=$this->db->query("SELECT *  from tablename where email = '".$email."' ");
    $row=$query1->result_array();
    if ($query1->num_rows()>0)
{
        $passwordplain = "";
        $passwordplain  = rand(999999999,9999999999);
        $newpass['password'] = md5($passwordplain);
        $this->db->where('email', $email);
        $this->db->update('employer_registration', $newpass);
        $mail_message='Dear '.$row[0]['name'].','. "\r\n";
        $mail_message.='Thanks for contacting regarding to forgot password,<br> Your <b>Password</b> is <b>'.$passwordplain.'</b>'."\r\n";
        $mail_message.='<br>Please Update your password.';
        $mail_message.='<br>Thanks & Regards';
        $mail_message.='<br>Your company name';
        require 'PHPMailerAutoload.php';
        require 'class.phpmailer.php';
        $mail = new PHPMailer;
        $mail->IsSendmail();
        $mail->isSMTP();
        $mail->SMTPAuth = true;
        $mail->Host = "hostname";
        $subject = 'Testing Email';
        $mail->AddAddress($email);
        $mail->IsMail();
        $mail->From = 'admin@***.com';
        $mail->FromName = 'admin';
        $mail->IsHTML(true);
        $mail->Subject = $subject;
        $mail->Body    = $mail_message;
        $mail->Send();
        if (!$mail->send()) {

            echo "<script>alert('msg','Failed to send password, please try again!')</script>";
        } else {

            echo "<script>alert('msg','Password sent to your email!')</script>";
        }
        redirect(base_url().'Jobseeker/index','refresh');
    }
    else
    {

        echo "<script>alert('msg','Email not found try again!')</script>";
        redirect(base_url().'Jobseeker/index','refresh');
    }
}

I hope you get an idea about forgot password gmail in codeigniter.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Related posts:

  1. How to change password in CodeIgniter?
  2. Send Forgot password by mail or message in PHP
  3. how to create forgot password Recovery (Reset) in php and MySQL?
  4. Reset Password Form Free bootstrap Widget Template
  5. PHP Change Password script using Mysqli
  6. How to Change User Password in Laravel 6
  7. How to change date format in PHP Codeigniter?
  8. codeigniter form validation callback multiple fields
  9. How To Send Mail in codeigniter from localhost serever?
Also Read This 👉   Send Windows Push Notification Services using PHP
codeigniter login and registration with forgot passwordforgot password gmail in codeigniterforgot password in codeigniterforgot password in codeigniter githubforgot password in codeigniter using ajaxforgot password using otp in phphow to change password in codeigniter framework

Post navigation

Previous Post:Bootstrap table border Examples
Next Post:insert and display data from database in codeigniter

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (64) Ajax (464) AngularJS (377) ASP.NET (61) Bio (109) Bollywood (108) Codeigniter (175) CSS (98) Earn Money (94) Education (65) Entertainment (131) fullform (87) Google Adsense (64) Highcharts (77) History (40) Hollywood (109) JavaScript (1359) Jobs (43) jQuery (1423) Laravel (1088) LifeStyle (53) movierulz4 (63) Mysql (1035) Mysqli (894) php (2133) Programming (2346) Python (99) Software (197) Software (94) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (149) Technology (2426) Tips and Tricks (130) Tools (215) Top10 (514) Trading (98) Trending (79) VueJs (250) Web Technology (116) webtools (201) wordpress (166) World (351)

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Info Grepper
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

© 2023 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype Guest Posting Sites