prevent users without confirmed email from logging in ASP.Net MVC with Identity 2

前端 未结 6 1141
遥遥无期
遥遥无期 2020-12-29 08:28

In microsoft Identity 2 there is ability to users can confirm there email addresses I downloaded Identity 2 sample project from here in this project there isn\'t any differ

6条回答
  •  一向
    一向 (楼主)
    2020-12-29 08:47

    Require email confirmation

    It's a best practice to confirm the email of a new user registration to verify they are not impersonating someone else (that is, they haven't registered with someone else's email). Suppose you had a discussion forum, and you wanted to prevent "yli@example.com" from registering as "nolivetto@contoso.com." Without email confirmation, "nolivetto@contoso.com" could get unwanted email from your app. Suppose the user accidentally registered as "ylo@example.com" and hadn't noticed the misspelling of "yli," they wouldn't be able to use password recovery because the app doesn't have their correct email. Email confirmation provides only limited protection from bots and doesn't provide protection from determined spammers who have many working email aliases they can use to register.

    You generally want to prevent new users from posting any data to your web site before they have a confirmed email.

    Update ConfigureServices to require a confirmed email: ​

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext(options =>
          options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
    
        services.AddIdentity(config =>
            {
                config.SignIn.RequireConfirmedEmail = true;
            })
            .AddEntityFrameworkStores()
            .AddDefaultTokenProviders();
    
        // Add application services.
        services.AddTransient();
    
        services.AddMvc();
    
        services.Configure(Configuration);
    }
    

提交回复
热议问题