Comments
Patrick Collands wrote: collands (AT) gmail com I'd be very grateful for an invitation. Thank you.
Cloud Expo on Google News

SYS-CON.TV

2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Click For 2008 West
Event Webcasts
Jon Box's .NET Blog: ASP.NET Membership Provider and Different Servers
I'm working on an application where I built a custom membership provider because of custom database scheme requirement

ASP.NET Membership Provider and Different Servers

I'm working on an application where I built a custom membership provider because of custom database scheme requirement.  My custom membership provider is using the hashed format for passwords and user answers.  I've got that working and now want to deploy the new application including the new provider.  Due to the encryption in ASP.NET being based on the MachineKey and wanting to share the data in development and early testing (ie. different web servers), I needed a MachineKey at the application level.

Thanks to an article in the patterns & practices ASP.NET 2.0 Security How To's, I found a snippet that would generate the keys for me.  I converted it to a Windows app so that I could just copy/paste the key into the Web.Config file in my development project.  While doing that, I discovered a small buy in the array declaration in thier sample.  It is corrected below.  To use the code, make a VB.NET WinForm project, add a multiline textbox and a button, paste this code in, and run.  I have made the code generate SHA1 for validation and AES for the decryption key.  Now I can run against the database from my development machine or the clients development server.  I can even copy the DB directly to my box for debugging purposes.

Imports System
Imports System.Text
Imports System.Security
Imports System.Security.Cryptography

Public Class Form1
    'from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/paght000007.asp
    'Generate Cryptographically Random Keys
    'To generate cryptographically random keys: 
    'Use the RNGCryptoServiceProvider class to generate a cryptographically strong random number. 
    'Choose an appropriate key size. The recommended key lengths are as follows: 
    ' For SHA1, set the validationKey to 64 bytes (128 hexadecimal characters). 
    ' For AES, set the decryptionKey to 32 bytes (64 hexadecimal characters). 
    ' For 3DES, set the decryptionKey to 24 bytes (48 hexadecimal characters).

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    CreateMachineKeyConfig()
End Sub

Private Sub CreateMachineKeyConfig()
   
Dim sb As StringBuilder = New StringBuilder()
    sb.AppendLine(
"<machineKey ")
   
sb.AppendLine(" validationKey = """ + GenRandomValues(128) + """")
    sb.AppendLine(
" decryptionKey = """ + GenRandomValues(64) + """")
    sb.AppendLine(
" validation = ""SHA1""")
    sb.AppendLine(
" decryption = ""AES""")
    sb.AppendLine(
" />")
   
Me.TextBox1.Text = sb.ToString()
End Sub

Private Function GenRandomValues(ByVal len As Integer) As String
    Dim buff((len / 2) - 1) As Byte 'JBox added the decrement b/c of VB array decl syntax
    Dim rng As New RNGCryptoServiceProvider()
    rng.GetBytes(buff)
    Dim sb As New StringBuilder(Len)
    Dim i As Integer
    For i = 0 To buff.Length - 1
        sb.Append(
String.Format("{0:X2}", buff(i)))
    Next i
    Return sb.ToString
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    CreateMachineKeyConfig()
End Sub

End Class



About Jon Box
Jon Box is an Architect Evangelist in Developer & Platform Evangelism with the Microsoft Corporation. He coauthored Building Solutions with the Microsoft .NET Compact Framework, published by Addison-Wesley, and blogs at http://blogs.msdn.com/jonbox/default.aspx.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Can you share the source code for your ASP.NET Membership Provider? I need to build a Membership Proivder for a custom application that has been built for Windows and I need to have the web (DNN 4.3.2) access the user database.

Thanks for any help.

I'm working on an application where I built a custom membership provider because of custom database scheme requirement. My custom membership provider is using the hashed format for passwords and user answers. I've got that working and now want to deploy the new application including the new provider. Due to the encryption in ASP.NET being based on the MachineKey and wanting to share the data in development and early testing (ie. different web servers), I needed a MachineKey at the application level.


Your Feedback
Brian Armstrong wrote: Can you share the source code for your ASP.NET Membership Provider? I need to build a Membership Proivder for a custom application that has been built for Windows and I need to have the web (DNN 4.3.2) access the user database. Thanks for any help.
Australia News Desk wrote: I'm working on an application where I built a custom membership provider because of custom database scheme requirement. My custom membership provider is using the hashed format for passwords and user answers. I've got that working and now want to deploy the new application including the new provider. Due to the encryption in ASP.NET being based on the MachineKey and wanting to share the data in development and early testing (ie. different web servers), I needed a MachineKey at the application level.
Latest Cloud Developer Stories
CloudBench Applications, Inc. announced its financial results for the three months and nine months ending September 30, 2009. All amounts are stated in Canadian dollars unless otherwise noted. Revenues from BasicGov, the Company's cloud computing solution for local government, gr...
The new contract is an industry first, with CSC being the first Microsoft partner to lead and win a cloud computing services agreement of this scale. Under terms of the contract, CSC will provide Royal Mail Group's 30,000 employees with access to new IT services using Microsoft's...
Operates in over 170 countries and is one of the world’s leading providers of communications solutions and services. Richard Tarboton talks for MeettheBoss.TV on his role as Head of Energy & Carbon for BT and what they are doing towards reducing carbon emissions.
CA is going to put its Agile Planner software on salesforce.com’s Force.com platform in the first half to accelerate development time and give users visibility over their development initiatives to reduce time-to-market. Customers are supposed to be able to accelerate the deploym...
Despite its uncertain fate Sun soldiers on. Monday it trotted out a cloud-based multiplatform desktop as a service for K-12 and community colleges that can run Windows, the Mac OS, Linux and Solaris applications to nearly any client device, including its own Sun Ray thin clients....
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON Featured Whitepapers
ADS BY GOOGLE

Breaking Cloud Computing News
CloudBench Applications, Inc. announced its financial results for the three months and nine months e...