I would like to implement an access account using email (with verification) including a reset password but most of the samples are using SQL server. Is there other mechanism or component which is DB agnostic (I'm currently using Postgresql)? A sample project is very much appreciated. Thank you
Loading

Manikandan MurugesanRank #300 · 8.4K reputationPosted Jul 2, 2024, 7:57 AM EDT
You can follow the link to work on setting up a sample project but it's on API and we can also do the same in MVC too: Building a Robust ASP.NET Core Web API with PostgreSQL (c-sharpcorner.com) https://www.c-sharpcorner.com/article/building-a-powerful-asp-net-core-web-api-with-postgresql/
Also, you can use explore more about Entity Framework to work on the other requirements
Aman GuptaRank #193 · 12.4K reputationPosted Jul 2, 2024, 8:56 AM EDT
Hi Sirch,
Below is a sample implementation using ASP.NET Core for the MVC framework. This example will show you how to set up email confirmation and password reset functionality.
Create a new ASP.NET Core MVC project:
dotnet new mvc -o EmailConfirmationDemo cd EmailConfirmationDemoAdd necessary packages:
Setup PostgreSQL in
appsettings.json:{ "ConnectionStrings": { "DefaultConnection": "Host=localhost;Database=yourdatabase;Username=yourusername;Password=yourpassword" }, "Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } }, "AllowedHosts": "*" }Create the DataContext:
using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; public class ApplicationDbContext : IdentityDbContext { public ApplicationDbContext(DbContextOptions options) : base(options) { } } public class ApplicationUser : IdentityUser { }Configure Services in
Startup.cs:public void ConfigureServices(IServiceCollection services) { services.AddDbContext(options => options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection"))); services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores(); services.AddControllersWithViews(); services.AddRazorPages(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); }Set up Identity pages:
Add the Identity UI scaffold to your project:
dotnet aspnet-codegenerator identity -dc ApplicationDbContext --files "Account.Register;Account.Login;Account.ConfirmEmail;Account.ForgotPassword;Account.ResetPassword"