0
在我的web應用程序,我創建一個隨機鹽,後來我通過這種鹽的哈希函數,就像這樣:等效密碼哈希函數vb.net
function generate_salt()
{
$max_length = 100;
$salt = hash('sha256', (uniqid(rand(), true)));
return substr($salt, 0, $max_length);
}
function hash_password($salt, $password)
{
$half = (int)(strlen($salt)/2);
$hash = hash('sha256', substr($salt, 0, $half) . $password . substr($salt, $half));
for ($i = 0; $i < 100000; $i++)
{
$hash = hash('sha256', $hash);
}
return $hash;
}
這是我vb.net
功能:
Public Shared Function CreateRandomSalt() As String
Dim mix As String = "[email protected]#$%^&*()_+=][}{<>"
Dim salt As String = ""
Dim rnd As New Random
Dim sb As New StringBuilder
For i As Integer = 1 To 100 'Lunghezza del salt
Dim x As Integer = rnd.Next(0, mix.Length - 1)
salt &= (mix.Substring(x, 1))
Next
Return salt
End Function
Public Shared Function Hash512(password As String, salt As String) As String
Dim convertedToBytes As Byte() = Encoding.UTF8.GetBytes(password & salt)
Dim hashType As HashAlgorithm = New SHA512Managed()
Dim hashBytes As Byte() = hashType.ComputeHash(convertedToBytes)
Dim hashedResult As String = Convert.ToBase64String(hashBytes)
Return hashedResult
End Function
現在我的問題是,當我創建一個新用戶或從我vb.net
的應用程序更新爲特定用戶的密碼,Web應用程序不能執行登錄我的用戶,也許密碼編碼是不同的,所以我需要一個012的功能或php
,讓我有相同的編碼。我該怎麼做?
[A PHP等效爲一個VB.NET密碼哈希函數(的可能的複製http://stackoverflow.com/questions/ 19457726/a-php-equivalent-for-a-vb-net-password-hash-function) – Plutonix
但是我有一個編碼爲256的 –
你是否儲存鹽或每次用戶嘗試登錄時生成一個隨機數? –