GetPassword exception in ASP.NET membership

26 09 2007

I tried a new method call today on ASP.NET MembershipUser.

Dim thisUser As MembershipUser = Membership.GetUser(thisUserName)

Then I called the following:

lbl.Text = thisUser.GetPassword

and got the following exception:

This Membership Provider has not been configured to support password retrieval.

After some investigation I noticed I needed the following in my web.config (Notice those in RED are the attributes that are required and were added in order to support the GetPassword method):

<membership>
<providers>
<clear/>
<add name=”AspNetSqlMembershipProvider”
connectionStringName=”247Db”
minRequiredPasswordLength=”4″
minRequiredNonalphanumericCharacters=”0″
type=”System.Web.Security.SqlMembershipProvider”
applicationName=”/247App”
enablePasswordRetrieval=”true”
requiresQuestionAndAnswer=”false”
passwordFormat=”Encrypted”
requiresUniqueEmail=”false” />
</providers>
</membership>

Following these additions, you need to add the following to web.config. There is a automatic key generator at the following: machineKey Generator

<machineKey validationKey="11D7D8362528F04266ACACDDEA7..."
decryptionKey=”4C0…”
validation=”SHA1″/>

You should then be able to support the GetPassword method().

If you don’t add the machineKey then you’ll get a different error as follows:

You must specify a non-autogenerated machine key to store passwords in the encrypted format. Either specify a different passwordFormat, or change the machineKey configuration to use a non-autogenerated decryption key.

Nice error hey? This is part & parcel of understanding a lot of the ASP.NET membership framework, you fix something somewhere, and you end up with a different error somewhere else. Its a big learning curve but a worthwhile one at that!


Actions

Information

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>