Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > How is Hash and Salt Computed Using ASP .net 2.0 built-in Controls

Reply
Thread Tools

How is Hash and Salt Computed Using ASP .net 2.0 built-in Controls

 
 
Ryan
Guest
Posts: n/a
 
      03-07-2007
How do the built in membership controls compute the password hash and
salt for storing in the memberstore? I am trying to create a custom
change password control but want to use the built-in login control. I
modified the following code from Microsoft to get it into VB but the
hashed password it creates is way longer than that created when I use
the Create User wizard. What am I doing wrong?

Public Shared Function ComputeHash(ByVal plainText As String,
_
ByVal hashAlgorithm As
String, _
ByRef saltBytes() As Byte)
_
As String

Dim saltsize As Integer
Dim passwordBytes() As Byte
Dim hash As HashAlgorithm

' If salt is not specified, generate it on the fly.


' Define min and max salt sizes.
'Dim minSaltSize As Integer
'Dim maxSaltSize As Integer

'minSaltSize = 8
'maxSaltSize = 8

' Generate a random number for the size of the salt.
'Dim random As Random
'random = New Random()

'Dim saltSize As Integer
'saltSize = random.Next(minSaltSize, maxSaltSize)


saltsize = 32
' Allocate a byte array, which will hold the salt.
saltBytes = New Byte(saltsize - 1) {}

System.Security.Cryptography.RNGCryptoServiceProvi der.Create().GetBytes(saltBytes)

' Convert the plain string password into bytes

passwordBytes =
UnicodeEncoding.Unicode.GetBytes(plainText)
Dim combinedBytes(passwordBytes.Length + saltBytes.Length
- 1) As Byte

' Append salt to password before hashing
System.Buffer.BlockCopy(passwordBytes, 0, combinedBytes,
0, passwordBytes.Length)
System.Buffer.BlockCopy(saltBytes, 0, combinedBytes,
passwordBytes.Length, saltBytes.Length)


' Fill the salt with cryptographically strong byte values.
'rng.GetNonZeroBytes(saltBytes)

' Because we support multiple hashing algorithms, we must
define
' hash object as a common (abstract) base class. We will
specify the
' actual hashing algorithm class later during object
creation.

' Make sure hashing algorithm name is specified.
If (hashAlgorithm Is Nothing) Then
hashAlgorithm = ""
End If

' Initialize appropriate hashing algorithm class.
Select Case hashAlgorithm.ToUpper()

Case "MD5"
hash = New MD5CryptoServiceProvider()
Case "SHA256"
hash = New SHA256Managed()

Case "SHA384"
hash = New SHA384Managed()

Case "SHA512"
hash = New SHA512Managed()

Case Else 'SHA1 = Default
hash = New SHA1Managed()

End Select

' Compute hash value of our plain text with appended salt.
Dim hashBytes As Byte()

hashBytes = hash.ComputeHash(combinedBytes)
' Append the salt to the hash
Dim hashPlusSalt(hashBytes.Length + saltBytes.Length) As
Byte
System.Buffer.BlockCopy(hashBytes, 0, hashPlusSalt, 0,
hashBytes.Length)
System.Buffer.BlockCopy(saltBytes, 0, hashPlusSalt,
hashBytes.Length, saltBytes.Length)

' Return the result.
ComputeHash = Convert.ToBase64String(hashPlusSalt)
End Function

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Silver and salt made digital Photocollector Digital Photography 1 06-11-2005 02:34 PM
Speech Apllication using SALT =?Utf-8?B?U2F0ZWVzaCBLdW1hciBFIEM=?= ASP .Net 0 01-02-2004 06:21 AM
Speech Web Application using SALT =?Utf-8?B?U2F0ZWVzaCBLdW1hciBFIEM=?= ASP .Net 0 12-31-2003 09:56 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57