+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / TelerikMembershipProvider

TelerikMembershipProvider

11 posts, 0 answered
  1. Sean
    Sean avatar
    271 posts
    Registered:
    31 May 2006
    14 Oct 2007
    Link to this post
    Hi Guys,

    Small bug for you, in the TelerikMembershipProvider I was trying to use GetUserNameByEmail to be able to allow people to login either by their username or by their password, but it kept returning null.  So I brought out Trusty Reflector, and this is what I found:

    public override string GetUserNameByEmail(string email) 
        SecUtility.CheckParameter(ref email, false, false, false, 0x80, "email"); 
        IList<User> list = this.Application.FindUsersByEmail(email, string.Empty); 
        if ((list.Count > 0) && (this.RequiresUniqueEmail && (list.Count > 1))) 
        { 
            throw new ProviderException(Messages.EmailConstraintMsg); 
        } 
        return null; 

    As you can see it does everything perfectly except for the last line where it returns null regardless of whether or not it finds the user.

    I tried to find a way to override the class to achieve this myself but most of the methods I tried using were all marked as internal, and I didn't want to spend too long looking for a solution to something so small...

    If you can think of any quick way around this or provide a hotfix I would appreciate it.

    Thanks
    Sean
  2. Yasen
    Yasen avatar
    121 posts
    Registered:
    18 May 2013
    15 Oct 2007
    Link to this post
    Hello Sean,

    Thanks for finding this bug, this is not the exact code, however the method always returns null. It is already fixed, changes will take effect in the service pack.

    For now you can use the FindUsersByEmail method from the TelerikMembershipProvider class.

    Your Telerik points have been updated.

    Greetings,
    Yasen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Sean
    Sean avatar
    271 posts
    Registered:
    31 May 2006
    16 Oct 2007
    Link to this post
    Hi Yasen,

    Thanks, yeah I figured the code wouldn't be exactly the same.

    It wasn't very easy getting the username from FindUsersByEmail but I got there in the end.  For anyone who is interested:

    1    void Login1_Authenticate(object sender, AuthenticateEventArgs e) 
    2    { 
    3        //check if an email is being used 
    4        if (this.Login1.UserName.Contains("@")) 
    5        { 
    6            int totalRows; 
    7            MembershipUserCollection users = UserManager.Default.FindUsersByEmail(this.Login1.UserName, 0, 1, null, out totalRows); 
    8            if (users.Count == 1) 
    9            { 
    10                foreach (MembershipUser user in users){ 
    11                    //change the login control username, if you don't do this the membership provider tries to use the email 
    12                    //address from this point on which doesn't work. 
    13                    this.Login1.UserName = user.UserName; 
    14                }                 
    15            }             
    16        } 
    17                         
    18        e.Authenticated = UserManager.Default.ValidateUser(this.Login1.UserName, this.Login1.Password); 
    19    } 

    Thanks for fixing the bug!

    Regards
    Sean

  4. aung maw
    aung maw avatar
    14 posts
    Registered:
    07 Apr 2006
    13 Mar 2009
    Link to this post
    Hi, Please let me know how can I override TelerikMembershipProvider function (or) add new function???

    Thanks,
  5. Sean
    Sean avatar
    271 posts
    Registered:
    31 May 2006
    14 Mar 2009
    Link to this post
    Hi Aung,

    How I did it was create a Class Library in Visual Studio and add a class that Inherits from the Telerik.DataAccess.AspnetProviders.TelerikMembershipProvider Class.

    But for simplicity you can add the class to App_Code, but it is more efficient to compile it in a separate library, but does require some knowledge of Class Libraries.

    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using System.Web.UI.HtmlControls; 
    using Telerik.DataAccess.AspnetProviders; 
     
    /// <summary> 
    /// Summary description for CustomMembershipProvider 
    /// </summary> 
    public class CustomMembershipProvider: TelerikMembershipProvider 
     
        public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int from, int maxRows, string sortExpr, out int totalRows) 
        { 
            return base.FindUsersByEmail(emailToMatch, from, maxRows, sortExpr, out totalRows); 
        } 
     


    With in that you can then override the methods or properties that you need to eg as I have above..

    Then you need to modify your web.config to use this new provider:

    <add name="Sitefinity" connectionStringName="DefaultConnection" type="CustomMembershipProvider, App_Code" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" passwordStrengthRegularExpression="" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" /> 

    The above code isn't the default so I would just copy the bold bits!

    Cheers
    Sean


  6. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    16 Mar 2009
    Link to this post
    Hi Sean,

    Thank you for providing the example!
    We have updated your Telerik account as a sign of gratitude to you.

    Sincerely yours,
    Georgi
    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.
  7. dimiter
    dimiter avatar
    13 posts
    Registered:
    25 Apr 2007
    16 Mar 2009
    Link to this post

    Hi

    I am using standard Create user control in Sitefinity. I want to hide the fields security question and security answer

    I  set up requiresQuestionAndAnswer="false" in   web.config

     

     


    but the fields are still there.  

    What I have to do to hede them?

    Kind regards

     

  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    16 Mar 2009
    Link to this post
    Hi dimiter,

    Try editing the template of CreateUserWizard control. It is located under ~/Sitefinity/UserControls/Login/.
    You can comment the following lines:

     <li> 
                                <asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">Security question:</asp:Label> 
                                <asp:TextBox ID="Question" runat="server"></asp:TextBox> 
                                <asp:RequiredFieldValidator ID="QuestionRequired" runat="server" ControlToValidate="Question" 
                                    ErrorMessage="Security question is required." ToolTip="Security question is required." 
                                    ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> 
                            </li> 
                            <li> 
                                <asp:Label ID="AnswerLabel" runat="server" AssociatedControlID="Answer">Security answer:</asp:Label> 
                                <asp:TextBox ID="Answer" runat="server"></asp:TextBox> 
                                <asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer" 
                                    ErrorMessage="Security answer is required." ToolTip="Security answer is required." 
                                    ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> 
                             </li> 

    Let us know if you need further assistance for your approach.

    All the best,
    Ivan Dimitrov
    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.
  9. dimiter
    dimiter avatar
    13 posts
    Registered:
    25 Apr 2007
    16 Mar 2009
    Link to this post

    Hi Ivan

    Thanks a lof about your assistance

    Kind regards

  10. Tarun
    Tarun avatar
    81 posts
    Registered:
    14 Jan 2009
    26 Apr 2010
    Link to this post
    Hi Sean,

    I am trying your code but it is giving an error "Object reference not set to an instance of an object." Please can you tell me where am I wrong.

    I am attaching a screen shot of error.

    public class CustomMembershipProvider :Telerik.DataAccess.AspnetProviders.TelerikMembershipProvider
    {
    public CustomMembershipProvider()
    {
    //
    // TODO: Add constructor logic here
    //
    }

        public override MembershipUserCollection FindUsersByEmail(string emailToMatch, int pageindex, int pagesize, out int totalRows)
        {
            totalRows = 0;
            // my logic...........
            // .......
            return base.FindUsersByEmail(emailToMatch, 0, 1, out totalRows);
        } 



    config setting...

    <membership defaultProvider="Sitefinity" userIsOnlineTimeWindow="15" hashAlgorithmType="">
    <providers>
    <clear/>
    <add name="Sitefinity" connectionStringName="DefaultConnection" type="CustomMembershipProvider, App_Code" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" passwordAttemptWindow="10" passwordStrengthRegularExpression="" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0"/>
    </providers>
    </membership>



    Thanks
    Tarun


  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    26 Apr 2010
    Link to this post
    Hello Tarun,

    You should override Initialize and initialize the DataConnection. You should also override the ApplicationName property and get the membership provider application name.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
11 posts, 0 answered