More in this section

Forums / Developing with Sitefinity / Expiry date for registered user

Expiry date for registered user

2 posts, 0 answered
  1. Ben
    Ben avatar
    1 posts
    17 Mar 2008
    13 Mar 2009
    Link to this post

    We have a business requirement to default newly registered users to expire after 30 days.  The administrators should be able to then extend this through the administration system as required.

    We've got half-way (OK, maybe a quarter) of the way there.  Within the profile settings in web.config, we've added an ExpiryDate of type DateTime.  This is appearing correctly on the User admin screen and is getting stored in the database in the UserMetaData table.

    In the <sec:ManageProfile> section of the CreateUserWizard page, we've added an ExpiryDate textbox but we don't want this to be editable and it should automatically be set to 30 days from today - any value entered here is correctly going in to the database, but we want to force a certain value.

    That's question 1!

    Question 2 is, once we have that correctly going in to the UserMetaData table, how do we configure the login check to include this as part of the authentication process and return an 'Account expired' error if today is greater than the value in that table?

    Thanks in advance
  2. Pepi
    Pepi avatar
    981 posts
    31 Jan 2017
    17 Mar 2009
    Link to this post
    Hi Ben,

    1. To achieve this, you need to modify CreateUserWizardControl.ascx user control:

     <sec:ManageProfile ID="ManageProfile" runat="server" Mode="Insert" GenerateButtonsInDefaultTemplate="false" > 
                        <asp:Label AssociatedControlID="ExpiryDate" ID="Label1" runat="server" Text="Expiry Date" /> 
                        <asp:TextBox ID="ExpiryDate" runat="server" Enabled="false" /> 

    protected void Page_Load(object sender, EventArgs e) 
            Control container = ManageProfile.Controls[0]; 
            ITextControl txtExpiryDate = (ITextControl)container.FindControl("ExpiryDate"); 
            MembershipUser user = UserManager.Default.GetUser(); 
            if (user != null
                ProfileBase profile = ProfileBase.Create(user.UserName); 
                DateTime expiryDate = (DateTime)profile.GetPropertyValue("ExpiryDate"); 
                txtExpiryDate.Text = expiryDate.ToString(); 
                txtExpiryDate.Text = DateTime.Now.AddDays(30).ToString(); 

    2. The required functionality should be implemented in the login page (the example below is for Sitefinity login page):

    void Login1_Authenticate(object sender, AuthenticateEventArgs e) 
            ProfileBase profile = ProfileBase.Create(this.Login1.UserName); 
            DateTime expiryDate = (DateTime)profile.GetPropertyValue("ExpiryDate"); 
            if (DateTime.Compare(expiryDate, DateTime.Now) < 0) 
                Login1.FailureText = "Account expired!"
                e.Authenticated = UserManager.Default.ValidateUser(this.Login1.UserName, this.Login1.Password); 

    Hope this helps.

    Sincerely yours,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
2 posts, 0 answered