Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • rasb 162 posts 218 karma points
    Feb 20, 2009 @ 15:32
    rasb
    0

    Custom membership provider

    Hi Guys,

    I am trying to implement a custom membership provider... and it isn't really going that well.

    I have created a class that extends the

    [code]umbraco.providers.members.UmbracoMembershipProvider[/code]

    and overridden the

    [code]ValidateUser(string username, string password) [/code]

    method. I have overridden the method to check my own SQL Server 2000 database for a username and password and return true if they match.

    I have then set up my Vista Ultimate machine with an Umbraco site, and I attach to the IIS process to debug the provider. This works and I can step through the process and the user is validated correctly so the ValidateUser method can return true.

    When I do this in the debug environment, my computer crashes (blue screens) at the point when true is returned. I can return false and everything works as it should.

    I have not done anything else than implement the ValidateUser. I am not sure what happens, since I can't really debug when my computer crashes.

    Am I missing something here?

    /rb

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Feb 20, 2009 @ 15:40
    Dirk De Grave
    0

    Hi,

    I've seen other posts of people implementing custom membership providers but had to
    change a few lines in the web.config regarding the role provider. I'll see if I dig up that post again.

    Regards,
    /Dirk

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Feb 20, 2009 @ 15:42
    Dirk De Grave
    0

    Ok, here's the post I was talking about: http://forum.umbraco.org/yafpostst8031Member-type.aspx

    Hope this helps.

    Regards,
    /Dirk

  • rasb 162 posts 218 karma points
    Feb 24, 2009 @ 10:54
    rasb
    0

    Hi Dirk,

    Thanks for the quick reply. I haven't tried it out yet, but will soon!

    /rb

  • jtmk 25 posts 20 karma points
    Feb 24, 2009 @ 15:30
    jtmk
    0

    Hi rasb,

    Can you tell me how you managed to override the login functionality in Umbraco? This is what I am trying to achieve in my site so that users do not have to login as it is on an Intranet.

    Regards

    James

  • rasb 162 posts 218 karma points
    Feb 24, 2009 @ 23:28
    rasb
    0

    Hi James,

    I haven't gotten it to work yet. But I will let you know what I am doing right now.

    I have created three classes, that derive from three classes in the namespace umbraco.providers.members.

    UmbracoMembershipProvider
    UmbracoProfileProvider
    UmbracoRoleProvider

    So far I have just overridden the method ValidateUser in the UmbracoMembershipProvider to handle login in the way I want it to. Here is my code for that:

    [code]public override bool ValidateUser(string username, string password)
    {
    System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
    string cmdText = "SELECT MemberPassword from Members WHERE MemberEmail = @email";
    cmd.CommandText = cmdText;
    cmd.Parameters.AddWithValue("@email", username);

    Object o = DBHelper.ExecuteSqlScalarQuery(cmd);

    if (!DBNull.Value.Equals(o) && o!=null)
    {
    string pw = (string)o;
    if (pw.Equals(password, StringComparison.CurrentCultureIgnoreCase))
    return true;
    }

    return false;
    }[/code]


    I think it will be a good idea to also override the Initialize method, but I haven't tried it yet.

    In your web.config file you then have to look for these lines and correct them to use your own Membership providers:

    [code]




    [/code]

    I think you have to also add a RoleProvider in order to make it work. That is what I am trying to do right now. I will let you know when I get it working. Then I will try to post a walk through of what I did.

    The umbraco.providers.members.UmbracoRoleProvider is in the compiled DLL I got from my sites bin directory, but for some reason not in the sourcecode I downloaded. The sourcecode also seems to be RC3 and not the final product.

    If you get this done before me, then please let me know! I will do the same!

    /rasb

  • rasb 162 posts 218 karma points
    Feb 25, 2009 @ 00:11
    rasb
    0

    I get an error when I try to use my custom provider, and it is:

    "No member with loginname: demousername Exists"

    I think it might be related to not using the member database provided with Umbraco by default. I am going to look further into that.

    Does anyone have any idea as to why it is looking in the Umbraco Membership database?

    /rasb

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies