Passwords must have at least one non alphanumeric character. is the description
of the PasswordRequiresNonAlphanumeric error in the IdentityResult
that UserManager.CreateAsync returns. Nothing threw in the lab: the call returned
Failed and a count afterwards found 0 rows in AspNetUsers. Print result.Errors, then either give the seed a password that meets the
rules or change the rules in options.Password.
A seed that only checks for an exception never sees this. In the lab the default rules
refused secret for three reasons at once, and abc for four.
The error
Console output of the seed, which prints the result and then each error's code and description:
Seed: Failed : PasswordRequiresNonAlphanumeric,PasswordRequiresDigit,PasswordRequiresUpper
PasswordRequiresNonAlphanumeric: Passwords must have at least one non alphanumeric character.
PasswordRequiresDigit: Passwords must have at least one digit ('0'-'9').
PasswordRequiresUpper: Passwords must have at least one uppercase ('A'-'Z').
...
With abc the list started with the length rule:
Seed: Failed : PasswordTooShort,PasswordRequiresNonAlphanumeric,PasswordRequiresDigit,PasswordRequiresUpper
PasswordTooShort: Passwords must be at least 6 characters.
...
Why it happens
CreateAsync checks the password against the configured rules and, when one of them
objects, returns a failed IdentityResult instead of throwing; the app went on to
start normally after the failed seed. With the default options the lab
saw four rules: a length of at least 6, a non-alphanumeric character, a digit and an uppercase
letter. secret is six lowercase letters, so it passed the length rule and failed the
other three. The result's ToString() lists only the codes; the sentences are in
Errors, one IdentityError per failed rule with Code and
Description.
The fix
Read the errors, and use a password that meets the rules:
...
var result = await users.CreateAsync(
new IdentityUser { UserName = "aisha.khan@example.test", Email = "aisha.khan@example.test" },
"Spring-2026x");
Console.WriteLine($"Seed: {result}");
foreach (var error in result.Errors)
Console.WriteLine($" {error.Code}: {error.Description}");
...
That printed Seed: Succeeded. If the rules themselves are wrong for your app, set
them where Identity is registered. This version accepted a long passphrase with no digit,
uppercase letter or symbol:
...
builder.Services.AddIdentityCore<IdentityUser>(options =>
{
options.Password.RequiredLength = 10;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireDigit = false;
options.Password.RequireUppercase = false;
})
.AddEntityFrameworkStores<AppDb>();
...
correct horse battery gave Seed: Succeeded, and secret
under the same options failed with one error only:
PasswordTooShort: Passwords must be at least 10 characters., so the description
follows the configured length. Only the four options above were tested here. The passwords in
the lab are the test's; a real seed reads its password from configuration or user-secrets,
never from source, and keeps the same check on result.Succeeded.
How it was reproduced
A dotnet new web -f net10.0 project on .NET SDK 11.0.100 with
Microsoft.AspNetCore.Identity.EntityFrameworkCore 10.0.10 and
Microsoft.EntityFrameworkCore.Sqlite 10.0.10, Identity registered with
AddIdentityCore<IdentityUser>().AddEntityFrameworkStores<AppDb>(), and a
startup seed that creates one fictional user. AppDb and lab.db are the
test's names. Six runs, each built with dotnet build and started with
dotnet bin\Debug\net10.0\IdnLab.dll --urls http://127.0.0.1:15620 (it printed
Hosting environment: Production): two weak passwords with the default options, one
that meets them, two with the relaxed options, and a last weak-password run that counted the rows.
The first run had no database file yet; each later run moved the previous file aside first.
Frequently asked
- Why does UserManager.CreateAsync not throw when the password is too weak?
- It returns an IdentityResult with Succeeded set to false. Check result.Succeeded and print result.Errors; each error has a Code such as PasswordRequiresNonAlphanumeric and a Description.
- How do I change the ASP.NET Core Identity password rules?
- Pass options to AddIdentityCore and set options.Password, for example RequiredLength, RequireNonAlphanumeric, RequireDigit and RequireUppercase. In the lab RequiredLength = 10 changed the message to 'at least 10 characters'.
- What are the default ASP.NET Core Identity password requirements?
- In the lab the default options refused passwords for being shorter than 6 characters and for missing a non-alphanumeric character, a digit or an uppercase letter.
If the user is created but cannot sign in, see 'Invalid login attempt' with the right password. More decoded errors in the Fixes category.