簡體   English   中英

CodeIgniter:更改控制器中的密碼

[英]CodeIgniter: changing password in controller

我試圖允許用戶更改我網站上的密碼。 我被卡在控制器中。 我的疑問是$sql = $this->db->select("*")->from("logins_table")->where('lt_username',$this->session->userdata('email'))->get(); 是否工作。

我的控制器:

<?php

class Changepw extends MY_Controller {

    public function Changepwd(){
    }

    public function reset() // we will load models here to check with database
    {
        $sql = $this->db->select("*")->from("logins_table")->where('lt_username',$this->session->userdata('email'))->get();

        foreach ($sql->result() as $my_info) {
            $db_password = $my_info->lt_password;
            $db_id = $my_info->lt_id;
        }

        if($this->input->post('opassword') == $db_password  && ($this->input->post('npassword') != '') && ($this->input->post('cpassword')!='')) { 
                $fixed_pw = mysql_real_escape_string(md5($this->input->post('npassword')));
                $update = $this->db->query("Update 'logins_table' SET 'lt_password'= '$fixed_pw'  WHERE 'id'= '$db_id'")or die(mysql_error());
                //$this->form_validation->set_message('change',"sucess");
    echo json_encode(array("success"=>true));

        }else {
            //$this->form_validation->set_message('change', "err");

            echo json_encode(array("success"=>false));

        }
        exit;
    } 
}

我的查看頁面是:

        <table width="95%" border="0" cellspacing="5" cellpadding="5">
        </tbody>
            <tr>
                <td width="35%" class="heading">Email</td>
                <td><input type="text" name="email" ></td>
            <tr>
                <td class="heading">Existing Password</td>
                <td><input type="password" name="opassword" ></td>
            </tr>
            <tr title="Ignore new password if you dont want to change password">
                <td   class="heading">New Password</td>
                <td><input type="password" name="npassword"></td>
            </tr>
            <tr>
                <td  class="heading">Confirm Password</td>
                <td><input type="password" name="cpassword"></td>
            </tr>

            <tr>
                <td>&nbsp;</td>
                <td><button name="Submit" id="forgotBtn" class="customBtn" value="Submit">Save changes</button>
                    </td>
                    <tr>
                <td>&nbsp;</td>
                <td ><div class="errorMsg" id="errMsg" style="display:none"> Error in updating </div></td>
            </tr>
            </tr> 
            </tbody>
            </table>
    </form>



$("#forgotBtn").on('click', function()
{

    $.post( "/changepw/reset",  $("#forgotForm").serialize(), // serializes the form's elements.
        function(data) {
            data = jQuery.parseJSON(data);
            if(data.error == false) {
                $("#successMsg").hide();
            }else{
                $("#errMsg").show();
            }
        } );
    return false;
});

謝謝。

我認為根據代碼,您的錯誤就在這里。

$this->input->post('opassword') == $db_password// this line

在數據庫中存儲密碼時,您使用了md5() ,但是在這里,您只是在檢查純文本,這是錯誤的

md5($this->input->post('opassword')) == $db_password

這應該對您有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM