views:

306

answers:

1

Hi all, I'm using the ASP.Net SqlMembershipProvider to manage my users. Here is my config:

<membership defaultProvider="SqlProvider" userIsOnlineTimeWindow="15">
      <providers>
       <clear />
       <add
        name="SqlProvider"
        type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
        connectionStringName="SiteDatabase"
        applicationName="WPR"
        minRequiredPasswordLength="6"
        minRequiredNonalphanumericCharacters="0"
        enablePasswordRetrieval="false"
        enablePasswordReset="true"
        requiresQuestionAndAnswer="false"
        requiresUniqueEmail="true"
        passwordFormat="Hashed" />
      </providers>
     </membership>

My problem is this: when I call Membership.CreateUser to create new users, the password is stored in the DB in hashed format with a salt - which is all good. However, when I call Membership.ChangePassword in an admin function, it is storing the password in plain text format. I really cannot understand this behaviour, since the config clearly says "Hashed" and creating a new user creates a hashed password.

Can anyone shed any light on this?

AHA, Ben

+1  A: 

Within the ChangePassword() method of the default ASPMembership provider, the password format for an existing user is retrieved from the database and is the format used to encode a new password for an existing user, and not the password format that is set in web.config, which may now specify a different format to use. You can see this for yourself by downloading the source code for the default providers.

My question is then, is the password being stored in clear text for a user who already had a password stored in clear text? You can check this easily by checking the value of the PasswordFormat field for the user in table aspnet_Membership. The values are:

Clear = 0,
Hashed = 1,
Encrypted = 2,
Russ Cam
Rus, you're a champ!!! That will be the problem - I'm testing this on users I originally setup manually in the DB with clear passwords. Thanks very much for the tip :)
Ben
No problem - I find it strange that this is the default behaviour. It's very straightforward to write your own provider and then implement password formatting exactly how you want it
Russ Cam