Copied to clipboard

Flag this post as spam?

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


  • Alexandre Demers 3 posts 73 karma points
    Jun 09, 2017 @ 19:30
    Alexandre Demers
    0

    ArgumentOutOfRangeException after programmaticaly creating a user and trying to connect to umbraco with said user

    Hi,

    I have a webservice that creates users for me using a pre-existing database. I can create the users and everything is fine. When I connect to Umbraco (using a user account that wasn't created by my program), I can see all of my users. But when I try to log in with one of the account I created, it gives me this error (and doesn't connect).

        System.ArgumentOutOfRangeException: Index and length must refer to a location within the string. Parameter name: length 
    
    
    Stacktrace 
    at System.String.Substring(Int32 startIndex, Int32 length)
       at Umbraco.Core.Security.MembershipProviderBase.StoredPassword(String storedString, String& salt)
       at Umbraco.Core.Security.MembershipProviderBase.CheckPassword(String password, String dbPassword)
       at Umbraco.Core.Security.MembershipPasswordHasher.VerifyHashedPassword(String hashedPassword, String providedPassword)
       at Microsoft.AspNet.Identity.UserManager`2.<VerifyPasswordAsync>d__3e.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.AspNet.Identity.UserManager`2.<CheckPasswordAsync>d__17.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Umbraco.Core.Security.BackOfficeUserManager`1.<CheckPasswordAsync>d__2.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Umbraco.Core.Security.BackOfficeSignInManager.<PasswordSignInAsyncImpl>d__4.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Umbraco.Core.Security.BackOfficeSignInManager.<PasswordSignInAsync>d__0.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Umbraco.Web.Editors.AuthenticationController.<PostLogin>d__f.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
    

    I think the problem is because of the password, but I've tried with numerous password lengh, and it doesn't change anything. No special characters either.

    Here's the code I've used :

     public string CreateAppUser(int id, string networkUserAccess, string firstName, string lastName, string password, bool isAdmin)
            {
                Umbraco.Core.Services.IUserService UserService = ApplicationContext.Current.Services.UserService;
                //generate a temporary email
                string emailAddress = string.Format("{0}.{1}@temporary.com", firstName, lastName);
                try
                {
                    if (UserService.GetByEmail(emailAddress) == null)
                    {
                        //creer le user
                        IUser newUser = UserService.CreateWithIdentity(networkUserAccess,
                            string.Format("{0}.{1}@temporary.com", firstName, lastName),
                            password, (isAdmin) ? "admin" : "editor");
                        //change parameters
                        newUser.Id = id;
                        UserService.Save(newUser);
                        return string.Format("User {0} successfuly created", newUser.Name);
                    }
                    return "The user's email (ID " + id + ") was already taken. The user hasn't been created";
                }
                catch (Exception ex)
                {
                    return "The user (ID " + id + ") couldn't be created : " + ex.Message;
                }
            }
    

    Does anyone know what the problem is?

  • Filur 20 posts 154 karma points
    Jun 19, 2017 @ 15:25
    Filur
    1

    Try using the Umbraco member service and save the password explicitly: umbracoMemberService.SavePassword(member, password);

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies