Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

FormsAuthentication.HashPasswordForStoringInConfigFile for VB

Posted on 2016-10-27
4
Medium Priority
?
72 Views
Last Modified: 2016-10-28
Hi Experts, I have an ASP.NET application that I am using to create hashes when registering a user. On the other hand I have a VB.NET application that is suppose to check this hash to authenticate the user. What is the VB.NET Windows Application equivalent of FormsAuthentication.HashPasswordForStoringInConfigFile please?

This is how I am generating the hash

Dim hash As String
        hash = FormsAuthentication.HashPasswordForStoringInConfigFile(Label1.Text & "salt", "SHA1")

Open in new window

0
Comment
Question by:takwirirar
  • 3
4 Comments
 
LVL 28

Accepted Solution

by:
Ark earned 2000 total points
ID: 41863426
String.Join("", Security.Cryptography.SHA1.Create.ComputeHash(
                System.Text.Encoding.UTF8.GetBytes(Label1.Text & "salt")).
                Select(Function(x) x.ToString("X2")))

Open in new window

0
 
LVL 28

Expert Comment

by:Ark
ID: 41863433
If you prefer function:
Private Function HashPasswordForStoringInConfigFile(password As String, passwordFormat As String) As String
    Dim ha As System.Security.Cryptography.HashAlgorithm
    If passwordFormat.Equals("sha1", StringComparison.OrdinalIgnoreCase) Then
        ha = Security.Cryptography.SHA1.Create
    ElseIf passwordFormat.Equals("md5", StringComparison.OrdinalIgnoreCase) Then
        ha = Security.Cryptography.MD5.Create
    Else
        Throw New ArgumentException("Invalid password format")
    End If
    Return String.Join("", ha.ComputeHash(
                 System.Text.Encoding.UTF8.GetBytes(password)).
                 Select(Function(x) x.ToString("X2")))
End Function

Open in new window

0
 
LVL 1

Author Closing Comment

by:takwirirar
ID: 41863532
Great! First solution works just fine although I  think the second is missing the salt?
0
 
LVL 28

Expert Comment

by:Ark
ID: 41864758
Second solution is a copy of FormsAuthentication.HashPasswordForStoringInConfigFile function. You can call it in the same way:
Dim hash As String
hash = HashPasswordForStoringInConfigFile(Label1.Text & "salt", "SHA1")

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question