久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

hash() 與 crypt() 函數(shù)比較

hash() vs. crypt() function comparison(hash() 與 crypt() 函數(shù)比較)
本文介紹了hash() 與 crypt() 函數(shù)比較的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我目前正在實施登錄系統(tǒng).我想將密碼和鹽存儲在數(shù)據(jù)庫中.現(xiàn)在我發(fā)現(xiàn)有一個 hash() 和一個 crypt() 函數(shù)似乎做了同樣的事情(對 SHA512 有效).

I'm currently implementing a login system. I want to store the password and the salt in a database. Now I found out that there is a hash() and a crypt() function which seems to do the same (valid for SHA512).

hash() 更新,似乎比 crypt() 支持更多的散列算法.或者我應該知道/關心其他任何差異嗎?

hash() is newer and seems to support more hashing alogrithms than crypt(). Or there any other differences I should know/care about?

function generatePasswordHash($password){
    $salt = base64_encode(mcrypt_create_iv(8));
    $calculatedPasswordHash = crypt($password, '$1$' . $salt . '$');

    return $calculatedPasswordHash;
}

結果看起來像 $1$Qh6ByGJ9$zLn3yq62egvmc9D7SzA2u.

這里是我的密碼檢查功能:

Here my password checking function:

function checkLoginData($username, $password){
    global $db;

    $sql = "SELECT * FROM users WHERE username = :username";
    $result = $db->ExecuteQuery($sql, array("username"=>$username));

    if(!empty($result)){
        $result = $result[0];
        $savedPasswordHash = $result['password'];
        $splitted = explode("$", $savedPasswordHash);
        $salt = $splitted[2];
        $calculatedPasswordHash = crypt($password, '$1$' . $salt . '$');

        if($savedPasswordHash === $calculatedPasswordHash){
            return true;
        }
    }

    return false;
}

推薦答案

使用 hash 進行散列,例如在完整性檢查中.直接使用指定的哈希算法.

Use hash for hashing, for example in integrity checks. It directly uses the specified hashing algorithm.

crypt 是一個特殊用途的函數(shù).它用于密碼散列和密鑰派生.您需要傳入一個鹽,它間接確定了所使用的散列方案.即使您選擇 CRYPT_SHA512,這也不是普通的 SHA512.這是一個使用 SHA512 作為構建塊的密鑰派生函數(shù).特別是這種方案是故意緩慢的(隱藏暴力攻擊)并且以安全的方式結合了鹽和密碼.

crypt is a special purpose function. It's used for password hashing and key derivation. You'll need to pass in a salt, which indirectly determines the hashing scheme used. Even if you choose CRYPT_SHA512 this isn't plain SHA512. It's a key derivation function that uses SHA512 as building block. In particular such a scheme is deliberately slow(hider brute-force attacks) and combines salt and password in a secure way.

對于日志系統(tǒng)中的密碼散列,crypt 顯然是正確的選擇.

For password hashing in a log system, crypt is clearly the right choice.

這篇關于hash() 與 crypt() 函數(shù)比較的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 免费看片在线播放 | 在线国产精品一区 | 激情免费视频 | 欧州一区二区 | 精品一二区| 91精品国产综合久久久久久丝袜 | 成人区精品 | 黄色片免费看 | 日日操夜夜摸 | 国产精品伦一区二区三级视频 | 在线一区二区三区 | 精品国产免费一区二区三区演员表 | 免费小视频在线观看 | 婷婷福利 | 嫩草一区二区三区 | 国产精品成人一区二区三区 | 最新国产精品 | 久久亚洲一区二区三区四区 | 精品一区二区av | 色又黄又爽网站www久久 | 日本a视频 | 综合久久av | 97起碰 | 午夜成人免费视频 | 久久夜色精品国产 | 久久男人| 久久精品视频在线观看 | 久久精品69 | 久久夜视频 | 最近日韩中文字幕 | 日韩一区二区在线视频 | 欧美激情视频一区二区三区在线播放 | 影音先锋中文字幕在线观看 | 视频一区二区三区四区五区 | 九九热在线观看视频 | 欧美日韩成人在线 | 毛片区 | 久久亚洲一区二区三区四区 | 婷婷色婷婷 | 黄久久久| 亚洲网站在线观看 |