AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Fails when password being too weak.

Open AnthonySavitt opened this issue 8 years ago • 15 comments

Hi, I am trying to get your final completed project file to work but when I try to run it I produce a 'HTTP Error 502.5 - Process Failure' page. I have also tried to follow the tutorial from the start, but this error gets produced as well at a certain point. I think it might have something to do with the SeedData but I am not sure. Any help would be fantastic because I'd love to be able to get something like this approve/reject method for a project I am working on. Thanks so much.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

AnthonySavitt avatar May 09 '18 00:05 AnthonySavitt

I just tested the starter and it runs fine. You might try putting a breakpoint in startup.

Rick-Anderson avatar May 09 '18 00:05 Rick-Anderson

Running the final project, i just tried the breakpoint like you said and it fails when doing the: try { SeedData.Initialize(services, testUserPw).Wait(); } Specifically, when it enters the 'await EnsureRole(serviceProvider, adminID, Constants.ContactAdministratorsRole);'

Breaking to the catch 'throw ex', right at the IR = await userManager.AddToRoleAsync(user, role); line.

Final error it produces is:

System.AggregateException HResult=0x80131500 Message=One or more errors occurred. Source=ContactManager StackTrace: at ContactManager.Program.Main(String[] args) in C:\Users\thean\Downloads\Docs-master\Docs-master\aspnetcore\security\authorization\secure-data\samples\final2\Program.cs:line 40

Inner Exception 1: ArgumentNullException: Value cannot be null.

Any further insight possibly? I hope the above erros can shed some kind of light I cannot see yet. Sorry, I am a beginner so trying my best to figure it out. Thanks so much for any help.

On Tue, May 8, 2018 at 5:43 PM, Rick Anderson [email protected] wrote:

I just tested the starter and it runs fine. You might try putting a breakpoint in startup.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/aspnet/Docs/issues/6288#issuecomment-387585441, or mute the thread https://github.com/notifications/unsubscribe-auth/AjeJeZY0qgL8kTYBiIv79U8SqZxaPBGbks5twjvIgaJpZM4T3he8 .

AnthonySavitt avatar May 09 '18 01:05 AnthonySavitt

Did you configure SeedUserPW?

Rick-Anderson avatar May 09 '18 01:05 Rick-Anderson

~The sample needs to be updated for the much better 2.1 versions of HTTPS. To get it running for now comment out~ ~// options.Filters.Add(new RequireHttpsAttribute());~

Rick-Anderson avatar May 09 '18 02:05 Rick-Anderson

The commenting out of that line did the trick! Thanks so much!!

On Tue, May 8, 2018 at 7:04 PM, Rick Anderson [email protected] wrote:

The sample needs to be updated for the much better 2.1 versions of HTTPS. To get it running for now comment out // options.Filters.Add(new RequireHttpsAttribute());

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/aspnet/Docs/issues/6288#issuecomment-387597401, or mute the thread https://github.com/notifications/unsubscribe-auth/AjeJedp2vcMtxpmTiXGGqwNwqeteivPkks5twk6ngaJpZM4T3he8 .

AnthonySavitt avatar May 09 '18 02:05 AnthonySavitt

You need to set up SSL in the project. Then it works with the SSL redirect. Right click on the project > properties > debug tab > enable SSL

Rick-Anderson avatar May 09 '18 02:05 Rick-Anderson

All that HTTPS/certs works much better with ASP.NET Core 2.1

Rick-Anderson avatar May 09 '18 02:05 Rick-Anderson

I enabled the SSL, thank you for that tip. I had seen something about enabling SSL but couldn't figure out how to access that at the time for some reason. Thanks again for all your help, it means a lot!

AnthonySavitt avatar May 09 '18 02:05 AnthonySavitt

I added a readme.md with that info. Hopefully I can update it for the much better 2.1 bits soon,.

Rick-Anderson avatar May 09 '18 02:05 Rick-Anderson

I'm getting this same error that AnthonySavitt described, ArgumentNullException: Value cannot be null when code IR = await userManager.AddToRoleAsync(user, role); runs. I tried configure SeedUserPW, update database and to use SSL. Also I tried to *comment out options.Filters.Add(new RequireHttpsAttribute()); *to use app.UseMvc(); instead of app.UseMvcWithDefaultRoute();
*put some defaultConnection string to appsettings.json (don't know if I should of done that). But this same error runs for both starter2 and for final2 program. I remember like 2 weeks ago those projects were running, but now that I installed RC 2.1, they don't want to run anymore

mtiganik avatar May 14 '18 15:05 mtiganik

I am having the same issue, has anyone got any ideas how to get this running? Thanks

tomaustin700 avatar May 22 '18 18:05 tomaustin700

Had the exact same issue and I just figured it out. For me (as usual) it was something dumb and I had to add an IdentityResult to the userManager.CreateAsync(user, testUserPw) line to finally see it. Here's the whole method:

    private static async Task<string> EnsureUser(IServiceProvider serviceProvider,
                                                string testUserPw, string UserName)
    {
        var userManager = serviceProvider.GetService<UserManager<ApplicationUser>>();
        IdentityResult IR = null;
        var user = await userManager.FindByNameAsync(UserName);
        if (user == null)
        {
            user = new ApplicationUser { UserName = UserName };
            IR = await userManager.CreateAsync(user, testUserPw);
        }

        return user.Id;
    }

My issue? The secret password I was setting for SeedUserPW didn't contain a capital letter. Ugh. Apparently that password must abide by the other password rules: capital letter, number, special character.

iamcraigw avatar May 22 '18 19:05 iamcraigw

@iamcraigw I thought I threw an exception when it failed to create a new user - for whatever reason. PW strength too low being the most common.

Rick-Anderson avatar May 22 '18 19:05 Rick-Anderson

ArgumentNullException: Value cannot be null.

That's a pretty big hint it didn't create the user. I'll add a code comment to that effect next update.

Rick-Anderson avatar May 22 '18 19:05 Rick-Anderson

@iamcraigw @Rick-Anderson Thanks, it was due to the password being too weak.

tomaustin700 avatar May 22 '18 21:05 tomaustin700