我應該如何將資料儲存到我的 MySQL 資料庫中,我應該將什麼型別指定給儲存鹽值的列?


鹽用於安全地儲存資料。如果我們必須安全地儲存使用者密碼,我們需要使用鹽。

$pwd=hash(hash($password) + salt)

然後將 $pwd 儲存在您的系統中,而不是真實密碼。

因此,問題是如何定義鹽值。以下是方法

// if (saltBytes == null)
{
   // Define min and max salt sizes.
   int minSaltSize = 4;
   int maxSaltSize = 8;

   // Generate a random number for the size of the salt.
   Random random = new Random();
   int saltSize = random.Next(minSaltSize, maxSaltSize);

   // Allocate a byte array, which will hold the salt.
   saltBytes = new byte[saltSize];

   // Initialize a random number generator.
   RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

   // Fill the salt with cryptographically strong byte values.
   rng.GetNonZeroBytes(saltBytes);
}

更新時間: 2020 年 6 月 27 日

181 次瀏覽

開啟你的 職業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.