Wednesday, November 26, 2008

A fix for the Azure TableStorageMemberProvider

I don't know if this is already known about or solved elsewhere... I couldn't spot it anywhere... but I'll post my fix here anyway - it's pretty trivial.

Problem: in my Azure I tried to implement a simple verification email scheme for user registration using a scheme similar to that described on http://www.aspcode.net/Requiring-email-verification-for-new-accounts.aspx

To do this I had to use the ProviderUserKey for each user.

However, when I looked at this, each user seemed to be coming back with a zero (empty) Guid.

Fix: Looking in the Azure supplied TableStorageMemberProvider, it seems that a providerKey is generated but is never actually stored in the table storage.

To fix this... look in
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion,
string passwordAnswer, bool isApproved, object providerUserKey,
out MembershipCreateStatus status)

then look down to

if (providerUserKey == null)
{
providerUserKey = Guid.NewGuid();
}
newUser.Password = pass;
newUser.PasswordSalt = salt;
newUser.Email = (email == null) ? string.Empty : email;

and add a line

if (providerUserKey == null)
{
providerUserKey = Guid.NewGuid();
}
#warning Fix implemented for zero'd providerUserKey
newUser.UserId = (Guid)providerUserKey;
newUser.Password = pass;
newUser.PasswordSalt = salt;
newUser.Email = (email == null) ? string.Empty : email;


That should work - it does for me :)

No comments:

Post a Comment