Solved

FormsAuthentication.HashPasswordForStoringInConfigFile for VB

Posted on 2016-10-27
4
59 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 28

Accepted Solution

by:
Ark earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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