Skip to main content
Version: 6.0.3

Login & Password Authentication

Login and password authentication is integrated into all .NET Identity Server templates except for the idserverempty template.

Overview

The core functionality for login and password authentication is provided by the NuGet package SimpleIdServer.IdServer.Pwd. This package encapsulates the authentication logic required for user login and password management in your identity server implementation.

cmd.exe
dotnet add package SimpleIdServer.IdServer.Pwd

Dependency Registration

To enable login and password authentication, the necessary dependencies are registered by invoking the AddPwdAuthentication() function from the fluent API, typically within the program.cs file. This function accepts a parameter that determines whether login and password authentication should be the default method for the identity server.

Configuration Options

The behavior of the authentication module is configurable via the appsettings.json file. To customize the module, add an IdServerPasswordOptions section to your configuration file. Within this section, you can set the following parameters:

ParameterDescription
NotificationModeSpecifies the communication channel used by the NuGet package to send a URL for updating the password. This could be via SMS, email, or another method.
ResetPasswordTitleDefines the title of the message sent to the user.
MessageContains the content of the message sent to the user. The message should include the URL leading to the password update form.
ResetPasswordLinkExpirationInSecondsSets the duration (in seconds) after which the password update URL will expire.
CanResetPasswordDetermines whether the option to reset the password (i.e., the link) should be displayed to the user.
EnableValidationEnable or disable the password validation
RequiredLengthGets or sets the minimum length that a password must have.
RequiredUniqueCharsGets or sets the minimum number of unique characters that a password must contain.
RequireNonAlphanumericGets or sets a flag indicating whether the password must contain at least one non-alphanumeric character.
RequireLowercaseGets or sets a flag indicating whether the password must contain at least one lowercase ASCII character.
RequireUppercaseGets or sets a flag indicating whether the password must contain at least one uppercase ASCII character.
RequireDigitGets or sets a flag indicating whether the password must contain at least one digit.
appsettings.json
  "IdServerPasswordOptions": {
"NotificationMode": "console",
"ResetPasswordTitle": "Reset your password",
"ResetPasswordBody": "Link to reset your password {0}",
"ResetPasswordLinkExpirationInSeconds": "30",
"CanResetPassword": "true",
"EnableValidation": "true",
"RequiredLength": "6",
"RequiredUniqueChars": "1",
"RequireNonAlphanumeric": "true",
"RequireLowercase": "true",
"RequireUppercase": "true",
"RequireDigit": "true"
}

An Example of a Program.cs File with Login and Password Authentication Enabled

Program.cs
var users = new List<User>
{
UserBuilder.Create("administrator", "password", "Administrator").SetEmail("adm@mail.com").SetFirstname("Administrator").Build()
};

var builder = WebApplication.CreateBuilder(args);
builder.AddSidIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryUsers(users)
.AddInMemoryLanguages(DefaultLanguages.All)
.AddPwdAuthentication(true);

var app = builder.Build();
app.Services.SeedData();
app.UseSid();
app.Run();

Example of the Authentication Window:

Authenticate