1
votes

i have a requirement to store Security Question and Answer, Their are columns in aspnet_Membership Table passwordQuestion and PasswordAnswer.i am using the following code

        UserInfo User = new UserInfo();
        User.AffiliateID = Null.NullInteger;
        User.DisplayName =txtDisplayName.Text;
        User.FirstName = txtFirstName.Text;
        User.LastName = TxtLastName.Text;
        User.Membership.Username = txtUserName.Text;
        User.Membership.Password = txtPassword.Text;
        User.Membership.CreatedDate = DateTime.Now;
        User.Membership.Email = txtEmail.Text;
        User.PortalID = this.PortalId;
        User.Username = txtUserName.Text;
        User.Email = txtEmail.Text;
        User.Membership.PasswordQuestion =TxtSecurityQuestion.Text;
        User.Membership.PasswordAnswer = TxtSecurityAnswer.Text;
        UserCreateStatus ucStatus = UserController.CreateUser(ref User);

I am not able to store Password Question and answer in aspnet_Membership Table

2

2 Answers

3
votes

If you set the requiresQuestionAndAnswer attribute to true in the SQL membership provider, DNN will automatically provide UI for and fill in those fields.

<membership defaultProvider="AspNetSqlMembershipProvider" userIsOnlineTimeWindow="15">
  <providers>
    <clear />
    <!-- Configuration for AspNetSqlMembershipProvider:
            connectionStringName="string"               Name corresponding to the entry in <connectionStrings> section where the connection string for the provider is specified
            maxInvalidPasswordAttempts="int"            The number of failed password attempts, or failed password answer attempts that are allowed before locking out a user?s account
            passwordAttemptWindow="int"                 The time window, in minutes, during which failed password attempts and failed password answer attempts are tracked
            enablePasswordRetrieval="[true|false]"      Should the provider support password retrievals
            enablePasswordReset="[true|false]"          Should the provider support password resets
            requiresQuestionAndAnswer="[true|false]"    Should the provider require Q & A
            minRequiredPasswordLength="int"             The minimum password length
            minRequiredNonalphanumericCharacters="int"  The minimum number of non-alphanumeric characters
            applicationName="string"                    Optional string to identity the application: defaults to Application Metabase path
            requiresUniqueEmail="[true|false]"          Should the provider require a unique email to be specified
            passwordFormat="[Clear|Hashed|Encrypted]"   Storage format for the password: Hashed (SHA1), Clear or Encrypted (Triple-DES)
            description="string"                        Description of what the provider does
            -->
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="SiteSqlServer" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="true" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="0" requiresUniqueEmail="false" passwordFormat="Encrypted" applicationName="DotNetNuke" description="Stores and retrieves membership data from the local Microsoft SQL Server database" />
  </providers>
</membership>
0
votes

You need to create a Membership object and attach it to your new user

Dim newMemebership As New UserMembership(User)
With newMemebership
    .CreatedDate = Date.Now()
    .Password = txtPassword.Text
    .PasswordAnswer = Answer
    .PasswordQuestion =  Question
     .etc....
End With
user.membership = newmembership

Sorry its VB but Im sure you can switch it over