MVC 4 Mobile App Login Error RRS feed

  • Question

  • User-118371376 posted

    I am still working on my 1st mobile application (Visual Studio 2010, VB.net) and I get a error every time i attempt to "Log in"  I am using the Nugent Simplemembership provider and I am sure that all of the plumbing is hooked up correctly.  Below is the error that I get in my AccountController.vb file.

    "Invalid length for a Base-64 char array." 

    This line -> Membership.ValidateUser(model.UserName, model.Password)  is underline by intellisense as the cause..

    Any Advice?

      ' POST: /Account/Login

        <AllowAnonymous()> _
        <HttpPost()> _
        Public Function Login(ByVal model As LoginModel, ByVal returnUrl As String) As ActionResult

            If ModelState.IsValid Then
                If Membership.ValidateUser(model.UserName, model.Password) Then
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe)

                    If Url.IsLocalUrl(returnUrl) Then
                        Return Redirect(returnUrl)
                        Return RedirectToAction("Index", "Home")
                    End If
                    ModelState.AddModelError("", "The user name or password provided is incorrect.")
                End If
            End If

            ' If we got this far, something failed, redisplay form
            Return View(model)
        End Function

    Monday, February 4, 2013 9:52 PM

All replies

  • User1943143334 posted


    Quickly replace the model.UserName and model.Password with some text, like this -

    Membership.ValidateUser("user1", "password")

    and try again. Check that works?

    Tuesday, February 5, 2013 2:09 AM
  • User-118371376 posted

    Thanks for the reply.  I added in some actual user account info as you suggested and i still get the same error as above "formatexception unhandled by user code" Invalid length for a Base-64 char array.

    Membership.ValidateUser("user123", "password123")

    Tuesday, February 5, 2013 8:43 AM
  • User-118371376 posted

    I have googled this for a couple of days and I can't seem to find anything related to this issue..

    Tuesday, February 5, 2013 8:44 AM
  • User1943143334 posted


    Can you show us the error details?

    Tuesday, February 5, 2013 9:47 AM
  • User-118371376 posted

       at System.Convert.FromBase64String(String s)
       at System.Web.Helpers.Crypto.VerifyHashedPassword(String hashedPassword, String password)
       at WebMatrix.WebData.SimpleMembershipProvider.CheckPassword(IDatabase db, Int32 userId, String password)
       at WebMatrix.WebData.SimpleMembershipProvider.ValidateUser(String username, String password)
       at System.Web.Security.Membership.ValidateUser(String username, String password)
       at RestorePro_Mobile.AccountController.Login(LoginModel model, String returnUrl) in c:\users\administrator\documents\visual studio 2010\Projects\RestorePro_Mobile\RestorePro_Mobile\Controllers\AccountController.vb:line 33
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
       at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
       at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()

    Tuesday, February 5, 2013 10:01 AM
  • User-118371376 posted

    I don't get a browser error.  After I click the login button I get diverted back to Visual Studio and I get the message that I initially posted.

    Tuesday, February 5, 2013 10:19 AM
  • User1943143334 posted


    Error looks like Conversion of hash password using Base64 encoding, which is done internally! 

    Can you try creating quick sample app and install SimpleMembership from Nuget and see whether you can reproduce the same!

    It's pretty weird that it's throwing this error, which usually will happen when you attemp to write your custom logic for the Base64 conversion!

    Wednesday, February 6, 2013 1:28 AM
  • User-118371376 posted

    Ok, I will give it a try. Thanks for getting back to me.

    Wednesday, February 6, 2013 9:54 AM
  • User-118371376 posted

    I setup a new application and i am getting an error that i can hopefully fix soon.

    Configuration Error

    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: Could not load file or assembly 'WebMatrix.Data, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

    I had to add a reference to the webmatrix.data dll and i also copied it to the bin folder and I am still getting the error.  I cleared the cache as well. 

    I have been stuck on the login issue for 4 days!!! Aaaargh...

    Wednesday, February 6, 2013 10:53 AM
  • User1943143334 posted


    Check this similar problem solved here - http://forums.asp.net/t/1818527.aspx/1 

    Hope it helps u...

    Wednesday, February 6, 2013 11:01 AM
  • User-118371376 posted

    Unfortunately that wasn't it either.  I created another new application on a different machine (Imac) and I had the same problem.  I am about ready to give up.....

    Wednesday, February 6, 2013 5:46 PM
  • User1943143334 posted


    Just hold on! Let us try to fix this - 

    1. Can you tell the steps followe by you?

    2. Can you provide me the link for the SimpleMembership which you have used? Is it a builtin one or third party membership?

    Thursday, February 7, 2013 12:47 AM
  • User-118371376 posted

    I went ahead and started a mvc 4 internet application. I will add some mobile pages to it.

    Thursday, February 7, 2013 9:56 AM