簡體   English   中英

Joomla 3.3-如何存儲用戶密碼?

[英]Joomla 3.3 - How to store user password?

我正在嘗試使用joomla 3.3.6將用戶密碼存儲在插件中。

根據Joomla文檔: https : //docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase

我創建了以下函數:

    /**
 * 
 * Update Password
 * 
 * @param unknown $idUser
 * @param unknown $password
 */
public function updateUserPassword($idUser, $password) {

    // Create a new query object.
    $query = $this->db->getQuery ( true );
    $value = JUserHelper::hashPassword($password);

    // Prepare the insert query.
    $query->update('#__users')
        ->set('password  = ' . $this->db->quote($value))
        ->where('id = ' . $idUser);

    // Set the query using our newly populated query object and execute it.
    $this->db->setQuery ($query);

    $updateResult = $this->db->execute ();
    if ($updateResult == false) {
        $errorMsg = $this->db->getErrorMsg ();
        var_dump($errorMsg);
    } else {
        echo "Update Done";
    }   
}

該代碼的執行沒有任何錯誤或警告,但表users中的用戶記錄保持不變。

$ query的值是:

UPDATE #__users
SET password  = '$2y$10$hO2MfDLfG5ICy2yhZWXZG.GCQ89vYw26KHVisXuuD8baRU9WtuDR.'
WHERE id = 192

$查詢看起來很好。 通過用我的自定義數據庫前綴替換#__來在mysqlworkbench中執行查詢,返回ok,我可以看到數據庫中的更改。

但是PHP代碼不起作用。

有人對此有任何線索嗎?

開發。

編輯代碼更改:在execute語句中添加錯誤處理。 消息“更新完成”被打印。

從您的代碼片段中,我看不到您如何確定代碼正在執行而沒有任何錯誤。

根據Joomla文檔https://api.joomla.org/cms-3/classes/JDatabaseDriver.html#method_execute,您的execute語句的返回值應為游標或false。

$updateResult = $this->db->execute();
if($updateResult == false) {
    $errorMsg = $this->db->getErrorMsg();
    //display this in your method of choice
}

根據您的服務器,可能還會有一個Web服務器錯誤日志條目。 在我的LAMP開發機器上,它在/ var / log / apache2 / error_log中

修改Joomla表記錄的替代方法

$user_record = new stdClass();
$user_record->id = $idUser;
$user_record->password = $password;

$result = JFactory::getDbo()->insertObject('#__users', $user_record, $idUser);

暫無
暫無

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

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