views:

122

answers:

2

Hi,

Could anyone give me any good link to log in function in monorail c#?

I am a newbie to monorail c# and need to implement one log in function.

Thank you.

Mealea

+1  A: 

Here's one from Ayende Rahien

Patrick Steele
+1  A: 

Like in Ayende's solution, the best way is to just use the ASP.net authentication mechanisms. Here's an example action on a LoginController:

        [AccessibleThrough(Verb.Post)]
    public void Authenticate(string username, string password, bool autoLogin, string returlUrl)
    {
        SomeWebServiceAuthenticationProvider wsSecurity = new SomeWebServiceAuthenticationProvider();


        bool isValid = wsSecurity.ValidateUser(username, password);

        if (isValid)
        {
            //first perform a logout to make sure all other cookies are cleared
            InternalLogout();

            FormsAuthentication.SetAuthCookie(username, autoLogin);
            PropertyBag["username"] = username;
            PropertyBag["password"] = password;
            PropertyBag["autoLogin"] = autoLogin;

            //redirect back to the Home page, or some other page
            if (!RedirectToPreviousUrl()) Redirect("home", "index");
        }
        else
        {
            Flash["auth_error"] = "Invalid user name or password.";
            RedirectToAction("Index");
        }
    }

You can substitute some other authentication mechanism in place of 'SomeWebServiceAuthenticationProvider"... the point here is that we're just calling the standard FormsAuthentication methods.

Marc
Mealea, can you choose an answer? This question has been sitting around for a while.
Marc