The Problem Solver

Tell me and I will forget
Show me and I will remember
Involve me and I will understand
- Confucius -

Google Ads

This Blog

Syndication

Search

Tags

News





  • View Maurice De Beijer's profile on LinkedIn

Community

Email Notifications

Explore

Archives

Using the ASP.Net membership provider in a Windows forms application part 2.

In my last blog entry I showed how to use the ASP.Net membership provider in a Windows application. In the sample I used the Membership.CreateUser() function to create a new user. However I had to supply quite a bit of information, like password question and answer, that I would not use in a typical windows application. Fortunately the Membership.CreateUser() also has an overload with just the username and password combination.

        Dim user As MembershipUser
        user = Membership.CreateUser("User2", "Password")
        Console.WriteLine(user.UserName)

 
However trying to use this overload results in the error: “The password-answer supplied is invalid.”. Additionally there might be some other properties you might like to change, like the requirement for at least one non alphanumeric character in the password. Even though these settings are exposed as properties they are read-only so setting them like:
Membership.MinRequiredNonAlphanumericCharacters = 0

Will not work. To change them we need to use the app.config so lets add one to the application. Add the following to the bottom of the <configuration> section:

<system.web>
    <
membership>
      <
providers>
        <
remove name="AspNetSqlMembershipProvider"/>
        <
add name="AspNetSqlMembershipProvider"
            
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
            
connectionStringName="LocalSqlServer"
            
enablePasswordRetrieval="false"
            
enablePasswordReset="true"
            
requiresQuestionAndAnswer="false"
            
applicationName="/"
            
requiresUniqueEmail="false"
            
passwordFormat="Hashed"
            
maxInvalidPasswordAttempts="5"
            
minRequiredPasswordLength="1"
            
minRequiredNonalphanumericCharacters="0"
            
passwordAttemptWindow="10"
            
passwordStrengthRegularExpression="" />
      </
providers>
    </
membership>
  </
system.web>

This removes the default membership provider as defined in the machine.config and adds the same one but this time with more relaxed password format and questions settings.

Now run the application again and this time we are allowed to add a user with just a username and password combination. Because of the relaxed password requirements even a password of just 1 single letter is accepted.

Stay posted for more.
 

Maurice de Beijer

www.TheProblemSolver.nl

Published Fri, Jan 13 2006 6:33 by Maurice

Comments

# Using the ASP.Net membership provider in a Windows forms application part 3.@ Saturday, January 14, 2006 4:57 AM











In my last two blog
entries I showed how to use the ASP.Net membership provider...

# re: Using the ASP.Net membership provider in a Windows forms application part 2.@ Monday, July 24, 2006 7:57 PM

Thanks! Very helpful ;)

by Rana

# re: Using the ASP.Net membership provider in a Windows forms application part 2.@ Tuesday, September 12, 2006 5:57 PM

You saved me! Thanks a lot!

Kevin

by Kevin

# re: Using the ASP.Net membership provider in a Windows forms application part 2.@ Monday, September 25, 2006 3:23 PM

thank you very much, you solve me a problem

by moly

# re: Using the ASP.Net membership provider in a Windows forms application part 2.@ Friday, May 04, 2007 3:42 AM

A very good article. keep up the goos work. :-) Cheers

by Jittu

# re: Using the ASP.Net membership provider in a Windows forms application part 2.@ Tuesday, June 05, 2007 3:50 PM

Thanks!  Helped me too!  Used time to have coffee with friend :)

by Max

# re: Using the ASP.Net membership provider in a Windows forms application part 2.@ Thursday, September 25, 2008 9:29 PM

Hello, thanks for the info.

But where did you get this part of the code?

type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"

Will it work with ASP.NET 3.5 (I'm using VisualStudio 2008).

Thanks in advance!

by Cesar Daniel

# re: Using the ASP.Net membership provider in a Windows forms application part 2.@ Friday, September 26, 2008 2:39 AM

There are several ways to get the fully qualified name of an assembly. I use Reflector where you can find it at the left bottom of the screen. Another way is by looking in C:\WINDOWS\assembly.

by Maurice

# re: Using the ASP.Net membership provider in a Windows forms application part 2.@ Friday, November 14, 2008 2:58 PM

Solved my issue... thanks.

by Andy

# re: Using the ASP.Net membership provider in a Windows forms application part 2.@ Saturday, February 28, 2009 8:34 PM

Tank you. I've been looking for this for days. I even tried WCF Authentication Service with less success. Thank you.

by Ron

# re: Using the ASP.Net membership provider in a Windows forms application part 2.@ Friday, April 17, 2009 1:51 PM

dude your color scheme makes the code hard to see.

by mark

# Sngholzx@ Monday, July 13, 2009 5:44 PM

jVos5c