HashPasswordForStoringInConfigFile

  • Thread starter Thread starter Softwaremaker
  • Start date Start date
S

Softwaremaker

Hi all,

I was just wondering if anyone here has the proper inner-workings of
HashPasswordForStoringInConfigFile method ? This method is part of the
FormsAuthentication found in the System.Web.Security namespace.

I am trying to replicate the same thing using the cryptography classes but I
cant seem to generate the same output. From the looks of it, the hashed
password generated seems to be in a HEX Format but I cant seem to do the
same for the crypto classes.

If any of the experts prowling around here can give me a rundown on the
inner plumbings of HashPasswordForStoringInConfigFile method, it will be
much appreciated.

--
Thank you very much

Warmest Regards,
Softwaremaker (WilliamT)
Software Architect
+++++++++++++++++++
 
It's simply a binhex representation of the passwords hash. XmlWriter has a
WriteBinHex method that will take a byte array. But it's simple to write one
your own, you just take byte by byte and write the hexadecimal
representation of each.

Jerry
 
Hi Jerry,

Thats exactly what I did...

I took that interpretation but it doesnt return the exact HEX representation
as reflected by HashPasswordForStoringInConfigFile method.

For reference, refer to code below

<code>
Public Function MyOwnHashPasswordForStoringInConfigFile(ByVal psValue As
String, ByVal hshName As String) As String

Dim hsh As HashAlgorithm = HashAlgorithm.Create(hshName)

Dim bytValue() As Byte = Encoding.Unicode.GetBytes(psValue)

Dim bytHash() As Byte = hsh.ComputeHash(bytValue)

Dim sb As New StringBuilder("")

Dim i As Integer

For i = 0 To bytHash.GetUpperBound(0) - 1

sb.Append(Hex(bytHash(i)))

Next

Return sb.ToString()

End Function

</code>

Any other suggestions ?

--
Thank you very much

Warmest Regards,
Softwaremaker (WilliamT)
Software Architect
+++++++++++++++++++
 
Softwaremaker said:
Hi Jerry,

Thats exactly what I did...

I took that interpretation but it doesnt return the exact HEX representation
as reflected by HashPasswordForStoringInConfigFile method.

For reference, refer to code below

<code>
Public Function MyOwnHashPasswordForStoringInConfigFile(ByVal psValue As
String, ByVal hshName As String) As String

Dim hsh As HashAlgorithm = HashAlgorithm.Create(hshName)

Dim bytValue() As Byte = Encoding.Unicode.GetBytes(psValue)

HashPasswordForStoringInConfigFile() uses Encoding.UTF8.GetBytes() - not
Unicode.
 
oic

Thanks mikeb for the helpful tip.

Thanks again.

--
Thank you very much

Warmest Regards,
Softwaremaker (WilliamT)
Software Architect
+++++++++++++++++++
 
Back
Top