Using Login control with Paladin

Posted Friday, December 02, 2005 2:39 PM by Shunjie
I experiment with the login control today and find that it is pretty easy and intuitive to use. However, if I am already using paladin for the data tier, then perhaps it will be good to combine this two to let them work together. This can be easily achieve by creating a custom class which inherits from System.Web.Security.MembershipProvider.

In my database, my schema contained a table named customer. The table contains a field named name and a field named password, which will be used to be authenticate against.


Using Paladin's BEWizard, I generate the entity classes and compiled it into a dll which will be referenced by my asp.net 2.0 application.

After which, I add a new class and named it cutixProvider. This provider need to inherits from System.Web.Security.MembershipProvider, and to validate the user, implements the ValidateUser method

Inside the ValidateUser method, I called the bc_validate method from the usermanagement class, a custom class which inherits from Paladin.Core.BusinessComponent. The usermanagement class will use 2 entity class generated by BEWizard, the cutix_customerList which is a collection of the customer object, and cutix_customer, which is the customer object itself. I implement the method as follows

//Inside usermanagment class, which inherits Paladin.Core.BusinessComponent
 public bool bc_validate(string username, string password)
    {       
        cutix_customerList cusList = new cutix_customerList();
        this.Populate(cusList, new FilterList(
            new Filter("name", Comparison.Equals, username)));
        return (cusList.Count > 0 &&
            cusList[0].password.Equals(password));      
    }

In this case, username is not the primary key of my database. If username is the primary key of your database, I believe the code can be simplify to:

 public bool bc_validate(string username, string password)
    {
        cutix_customer cus = new cutix_customer(username);
        this.Populate(cusList);
        return cus.password.Equals(password);
           
    }


In the cutixProvider itself, I implement the ValidateUser method as follows

   public override bool ValidateUser(string username, string password)
    {
        usermanagement usermanager =  new usermanagement();
        return usermanager.bc_validate(username, password);
    }

Now what is left is to edit the web config to for the login controls to use cutixProvider:

<!--config for paladin -->
<configSections>
        <sectionGroup name="Paladin">
            <sectionGroup name="data">
                <section name="database" type="Paladin.Configuration.DatabaseSectionHandler,Paladin.Core"/>
            </sectionGroup>
        </sectionGroup>
    </configSections>
    <Paladin>
        <data>
            <database>
                <connection name="default" engine="mssql" encrypted="false" connectionString="Server=<your server>;Database=<your database>;User Id=<userid>;Password=<password>;pooling=true"/>
            </database>
        </data>
    </Paladin>
<!--end config for paladin-->

<system.web>
        <customErrors mode="Off"/>
        <trust level="Full" originUrl="" />
        <authorization>
                  <allow users="*" />
            </authorization>
            <authentication mode="Forms">
                 <forms name=".ASPXAUTH" loginUrl="~/admin/default.aspx" protection="Validation" timeout="20"/>
            </authentication>
            <membership defaultProvider="cutixProvider" userIsOnlineTimeWindow="15">
              <providers>
                    <clear/>
        <add name="cutixProvider"
          type="cutixProvider"
          enablePasswordRetrieval="true"
          enablePasswordReset="true"
          requiresQuestionAndAnswer="false"
          applicationName="/"
          requiresUniqueEmail="true"
          passwordFormat="Clear"
          description="Stores and retrieves membership data from Paladin"
        />
      </providers>
    </membership>
    </system.web>

Once this is done, simple drag in a login control and it will work =)
Filed under: , ,

Comments

# ASP.Net 2.0 + Ajax.net + Paladin = Foodlane.sg

Thursday, July 20, 2006 5:08 PM by Shunjie's blog

In this post I will be talking about the technologies I used to built Foodlane.sg. I tried to refrain