Developer forum

Forum » Development » Custom Login procedure

Custom Login procedure

Nuno Aguiar
Reply

Hi,

 

I have a client with a special request. I need a two step validation in the website. Password + User Login.

 

I managed to get this working, but now, he need's the password to be dynamic. Is there any notifier I can subscribe to in order to perform my own password validation? The ideia is to use the Dynamicweb engine, but manipulate the args.

 

Nuno


Replies

 
Nuno Aguiar
Reply

Hi,

 

So no brilliant ideas anyone?

 

Nuno

 
Morten Bengtson
Reply

Hi Nuno,

What do you mean by "he need's the password to be dynamic"?

Whats your current working solution? Standard page password and extranet login or something else?

 

 
Nuno Aguiar
Reply

Hi Morten,

 

Basically, I have to check if the password is valid against a specific table per website. But the password should only get them so far, because later they should need to login (extranet) to shop and check previous orders.

 

So I need to catch the password arg, check if it's a valid password and let Dynamicweb take over.

 

The problem is that the password module/feature expect a string, and I need to check it against an array of values or partial value (password = e-mail ; if domain is valid, then user can see website)

 

Nuno

 
Morten Snedker
Reply

Aren't you basically talking about your OWN login (with no regards to Extranet login) that you use for "master" validation, and then followingly you perform an Extranet login (or reject if password is not valid)?

 

And if "master" password is valid, should the user then followingly login with ordinary username/password?

 

Regards /Snedker

 

 
Morten Bengtson
Reply
You could implement your own login logic in a notificationsubscriber for Dynamicweb.Notifications.Standard.Page.Loaded

This solution requires that you setup standard extranet permissions and then give access to extranet users that you can use for actually logging in (one user per site).

You can use a custom extranet login template that only contains a "sitepassword" field (don't include "username" or "password" fields as they will trigger the standard login).

I hope that the following snippet of code can give you an idea of how to implement your custom login, but I have NOT tested this code, so I can't guarantee that it actually works :)

public override void OnNotify(string notification, NotificationArgs args)
{
    var parameters = args as LoadedArgs;

    // Get the current pageview
    var pageView = parameters.pageview;

    // Get the password that was submitted in the custom login form
    var password = Base.Request("sitepassword");

    if (IsValidPassword(password, pageView))
    {
        // Get an existing extranet user with a username matching the current area id
        var user = User.GetUserByUserName("Area" + pageView.AreaID);

        // Log in
        var security = new Security();
        security.ExtranetLogin(user.UserName, user.Password);
    }
}

private bool IsValidPassword(string password, PageView pv)
{    
    if (string.IsNullOrEmpty(password))
    {
        return false;
    }

    // TODO: Verify that password exists in custom table - maybe also use pv.AreaID or something
}

And the login template to use with it...

<form action="" method="post">
    <label>Password: <input name="sitepassword" value="" type="password" /></label>
    <input type="submit" value="Login" />
</form>

Let me know if this works for you :)

 

 
Nuno Aguiar
Reply

Morten Snedker,

Yes, you are right. The best idea was to simulate the password procedur, but I can't find the correct notifications for it.

 

Morten Bengtson,

Your idea is great, but I cannot use it, because:

  - custom "password" validation should give access to some pages/contents

  - extranet password is needed to some special pages

 

Currently I achieve this by setting up password in all pages + extranet permissions in special pages.

 

If there was a notification to manage the password feature, instead of the extranet login. Maybe if I use the Dynamicweb.Notifications.Standard.Page.Loaded notification, check for the password and if valid, change the arg to the static value for the page, it might just work!

 

I'll give it a try, but thanks for the input.

 

Nuno

 
Morten Bengtson
Reply
This post has been marked as an answer
  • custom "password" validation should give access to some pages/contents
    • That is why the ExtranetLogin part is there. The user will be logged in as a special "area user" that you can use to set permission on pages etc.
  • extranet password is needed to some special pages
    • Then you just set up other permission settings on those pages and the user will be prompted to login again, now as a real extranet user.

If you prefer to make changes to the page password, you can do it like this:

PageView.Current().Page.set_Value("PagePassword", "whatever");

 

 

Votes for this answer: 1
 
Nuno Aguiar
Reply

Hi Bergtson,

 

Dumb me... I will give it a go as well. Thanks a lot

 

Nuno

 
Jais Edelmann
Reply

Couldent you just use Dynamicweb User Groups? And a Customfield on the user? So if user inputs myspecialfieldinput into your customfield then move user to group X instead of Y ?

 

You must be logged in to post in the forum