Solved

FormsAuthentication.HashPasswordForStoringInConfigFile for VB

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

Accepted Solution

by:
Ark earned 500 total points
Comment Utility
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 27

Expert Comment

by:Ark
Comment Utility
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
Comment Utility
Great! First solution works just fine although I  think the second is missing the salt?
0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now