Solved

FormsAuthentication.HashPasswordForStoringInConfigFile for VB

Posted on 2016-10-27
4
66 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

687 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