简体   繁体   English

在 ASP.Net Core 应用程序中使用弱密码时出现错误

[英]I get an error when I use weak password on my in ASP.Net Core application

This error does not happen when I test the application in development mode on my PC, but on the remote server it does.当我在我的 PC 上以开发模式测试应用程序时,不会发生此错误,但在远程服务器上会发生。 The app verify if user exist and the password requirements, but if I use a password like "1234" the app give me this error, but it does happen if I use a password like "@juan147-lop4s785"该应用程序验证用户是否存在以及密码要求,但如果我使用像“1234”这样的密码,应用程序会给我这个错误,但如果我使用像“@juan147-lop4s785”这样的密码,它就会发生

在此处输入图像描述

This is the launchSettings.json file这是launchSettings.json文件

{
 "iisSettings": {
   "windowsAuthentication": false,
   "anonymousAuthentication": true,
   "iisExpress": {
   "applicationUrl": "http://localhost:63322",
   "sslPort": 44361
 }
},
"profiles": {
 "IIS Express": {
  "commandName": "IISExpress",
  "launchBrowser": true,
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Production"
    //"ASPNETCORE_ENVIRONMENT": "Development"
  }
},
"UniJobs": {
  "commandName": "Project",
  "launchBrowser": true,
  "applicationUrl": "https://localhost:5001;http://localhost:5000",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Production"
    //"ASPNETCORE_ENVIRONMENT": "Development"
   }
  }
 }
}

and this us mi Startup.cs file这是我们的Startup.cs文件

namespace UniJobs
{
public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));

        services.AddDefaultIdentity<Usuarios>(options => options.SignIn.RequireConfirmedAccount = true)
            //Incluye los roles de los usuarios a la app
            .AddRoles<IdentityRole>()
            .AddEntityFrameworkStores<ApplicationDbContext>();

        services.AddControllersWithViews();
                    
        services.AddRazorPages();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseDeveloperExceptionPage();

        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseRouting();
        app.UseSession();

        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
            endpoints.MapRazorPages();
        });
    }
  }
}

It's likely that when creating a user, you're not checking whether it was successful or not and therefore when your "weak password" doesn't meet the default Identity options, it fails to create the user and then the database complains about the missing foreign key, resulting in your error.很可能在创建用户时,您没有检查它是否成功,因此当您的“弱密码”不符合默认身份选项时,它无法创建用户,然后数据库抱怨丢失外键,导致你的错误。

Have a look here for the default Identity password options and how to customise them. 在这里查看默认身份密码选项以及如何自定义它们。

If you're using UserManager to create the user, you just need to check if it there were any errors and respond accordingly, something like the below:如果您使用UserManager创建用户,您只需要检查它是否有任何错误并做出相应的响应,如下所示:

var result = await UserManager.CreateAsync(user, password);

if(!result.Succeeded)
    return result.Errors.Select(x => x.Description);

var roleResult = await UserManager.AddToRoleAsync(user, "User");

if (!roleResult.Succeeded)
    return roleResult.Errors.Select(x => x.Description);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的asp.net网络应用程序出现错误 - I get an error in my asp.net web application 如何在我的 ASP.NET Core 应用程序中使用 Startup.cs 之外的服务? - How can I use a service outside of Startup.cs in my ASP.NET Core Application? 如何在ASP.net Core应用程序中同时使用Bearer和Cookie身份验证? - How can I use both Bearer and Cookie authentication in my ASP.net Core application? 启动应用程序时发生错误,一旦我在 IIS 上运行我的 ASP.NET 核心项目 - An error occurred while starting the application, once I run my ASP.NET Core project on IIS 当我想在 ASP.NET 核心 Web API 中的构造函数中使用 select 时出现错误 - I get an error when I want to select in constructor in ASP.NET Core Web API 当我在Asp.net Core(MVC)中搭建控制器时,出现代码生成错误 - When I scaffold a controller in Asp.net Core (MVC), I get a Code generation error 当我在查询中使用“包含”时,ASP.NET Core Web API 返回不完整的 JSON 数据 - ASP.NET Core Web API returns incomplete JSON data when I use 'include' in my query 我可以在asp.net应用程序中使用Lync api吗? - Can I use a Lync api in my asp.net application? 如何在使用 EF 的 asp.net core 3.1 MVC 应用程序中正确使用我的 SQLite 数据库? - How do I properly use my SQLite db in my asp.net core 3.1 MVC application using EF? 当我将 ASP.NET Core web 应用程序部署到 Azure 时,为什么没有检测到我的环境设置? - Why are my environment settings not being detected when I deploy my ASP.NET Core web application to Azure?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM