Copied to clipboard

Flag this post as spam?

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


  • Gheorghe Balan 3 posts 73 karma points
    Mar 11, 2016 @ 14:16
    Gheorghe Balan
    0

    Issue with authentication

    Hi, I am using a simple .net Membership Validator to authenticate users logging in to the website. The authentication fails every time without any reason. No error is being reported to the logs..I have no idea what's causing it...

     [System.Web.Mvc.HttpPost]
        [System.Web.Mvc.ActionName("Login")]
        public ActionResult LoginPost(Models.Customer.LoginModel model)
        {
            var provider = Membership.Provider;
            string name = provider.ApplicationName; // Get the application name here
            if (System.Web.Security.Membership.ValidateUser(model.UserName, model.Password))
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {...}
        }  }
    
  • Rhys Hamilton 20 posts 89 karma points
    Mar 11, 2016 @ 15:27
    Rhys Hamilton
    0

    I may be wrong, but I believe that it fails because it cannot validate the user.

    Within your LoginModel, add a new property:

    public bool RememberMe {get; set;}

    Then, within your controller:

     using <namespace>.Models; // Your namespace
    
    public ActionResult LoginPost(LoginModel model)
    {
        if (ModelState.IsValid)
        {
            if (Membership.ValidateUser(model.Username, model.Password))
            {
                FormsAuthentication.SetAuthCookie(login.Username, login.RememberMe);
    
              // Redirect to a page, or whatever else you want to do here
            }
        }
    }
    

    If this fails, I can attach working models/controllers. :)

  • Gheorghe Balan 3 posts 73 karma points
    May 30, 2016 @ 09:07
    Gheorghe Balan
    0

    Yes Rhys,

    You are correct - the Authentication cookie did the trick - that was the missing element in my code.

    However - having figured out that part - there is a second question I need to ask.

    Would this form of authentication work as long as the users are being created in Umbraco CMS dashboard only ? The challenge I am facing is data handling where I have another database which contains information about users - i.e. not the Umbraco database. At the moment there is a way of sort of by-passing the Umbraco authentication by using a standard user which has to be created in Umbraco, and then setting a session object with details of that user based on the data coming from the other database.

    This method works ok - but it has its drawbacks - in the meaning that the top-level object will always reflect that standard user.

    Is there a nice way of solving this problem - without manually creating the users in Umbraco dashboard ? A solution should also consider the possibility of updating and deleting users in either of the databases, and having the changes propagate from one place to the other. So reply to this if you have any ideas.

Please Sign in or register to post replies

Write your reply to:

Draft