diff --git a/aspnetcore/security/authentication/accconfirm.md b/aspnetcore/security/authentication/accconfirm.md index 4983827580..efecd35bdc 100644 --- a/aspnetcore/security/authentication/accconfirm.md +++ b/aspnetcore/security/authentication/accconfirm.md @@ -78,7 +78,11 @@ Add the `[RequireHttps]` attribute to each controller. The `[RequireHttps]` attr 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, you would want to prevent "bob@example.com" from registering as "joe@contoso.com". Without email confirmation, "joe@contoso.com" could get unwanted email from your app. Suppose Bob accidentally registered as "bib@example.com" and hadn't noticed it, he wouldn't be able to use password recovery because the app doesn't have his 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 been confirmed by email, an SMS text message, or another mechanism. In the sections below, we will enable email confirmation and modify the code to prevent newly registered users from logging in until their email has been confirmed. +You generally want to prevent new users from posting any data to your web site before they have a confirmed email. In the sections below, we will enable email confirmation and modify the code to prevent newly registered users from logging in until their email has been confirmed. + +Update `ConfigureServices` to require a confirmed email: + +[!code-csharp[Main](accconfirm/sample/WebApplication3/src/WebApplication3/Startup.cs?highlight=11&name=snippet1)] ### Configure email provider diff --git a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/Startup.cs b/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/Startup.cs index 4f3821297e..1e9d468ce2 100644 --- a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/Startup.cs +++ b/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/Startup.cs @@ -41,6 +41,7 @@ namespace WebApplication3 public IConfigurationRoot Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. + #region snippet1 public void ConfigureServices(IServiceCollection services) { // Add framework services. @@ -49,7 +50,10 @@ namespace WebApplication3 services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); - services.AddIdentity() + services.AddIdentity(config => + { + config.SignIn.RequireConfirmedEmail = true; + }) .AddEntityFrameworkStores() .AddDefaultTokenProviders(); @@ -65,6 +69,7 @@ namespace WebApplication3 options.Filters.Add(new RequireHttpsAttribute()); }); } + #endregion // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) diff --git a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/_references.js b/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/_references.js deleted file mode 100644 index 9b2a79166f..0000000000 --- a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/_references.js +++ /dev/null @@ -1,7 +0,0 @@ -/// -/// -/// -/// -/// -/// -/// diff --git a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/css/site.css b/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/css/site.css deleted file mode 100644 index b64212d5a4..0000000000 --- a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/css/site.css +++ /dev/null @@ -1,44 +0,0 @@ -body { - padding-top: 50px; - padding-bottom: 20px; -} - -/* Wrapping element */ -/* Set some basic padding to keep content from hitting the edges */ -.body-content { - padding-left: 15px; - padding-right: 15px; -} - -/* Set widths on the form inputs since otherwise they're 100% wide */ -input, -select, -textarea { - max-width: 280px; -} - -/* Carousel */ -.carousel-caption p { - font-size: 20px; - line-height: 1.4; -} - -/* buttons and links extension to use brackets: [ click me ] */ -.btn-bracketed::before { - display:inline-block; - content: "["; - padding-right: 0.5em; -} -.btn-bracketed::after { - display:inline-block; - content: "]"; - padding-left: 0.5em; -} - -/* Hide/rearrange for smaller screens */ -@media screen and (max-width: 767px) { - /* Hide captions */ - .carousel-caption { - display: none - } -} diff --git a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/favicon.ico b/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/favicon.ico deleted file mode 100644 index a3a799985c..0000000000 Binary files a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/favicon.ico and /dev/null differ diff --git a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/images/banner1.svg b/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/images/banner1.svg deleted file mode 100644 index 1ab32b60b8..0000000000 --- a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/images/banner1.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/images/banner2.svg b/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/images/banner2.svg deleted file mode 100644 index 9679c604d0..0000000000 --- a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/images/banner2.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/images/banner3.svg b/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/images/banner3.svg deleted file mode 100644 index 9be2c2503c..0000000000 --- a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/images/banner3.svg +++ /dev/null @@ -1 +0,0 @@ -banner3b \ No newline at end of file diff --git a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/images/banner4.svg b/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/images/banner4.svg deleted file mode 100644 index 38b3d7cd1f..0000000000 --- a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/images/banner4.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/js/site.js b/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/js/site.js deleted file mode 100644 index 82ecce7b4a..0000000000 --- a/aspnetcore/security/authentication/accconfirm/sample/WebApplication3/src/WebApplication3/wwwroot/js/site.js +++ /dev/null @@ -1 +0,0 @@ -// Write your Javascript code.