dotnet / dotnet/aspnetcore

Identity: Adding user to role gives an Invalid Username error (UserManager.cs).

Open
#46,806 2 comments 0 reactions 0 assignees View on GitHub
area-identity investigate
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

Its possible to create users with Turkish characters like ı or even with whitespaces. But when assigning a role through the UserManager returns an identityerror with Invalid Username.

### Expected Behavior

Example:
create user with username: Yazıcı .
> user created.

assign role to user with UserManager

> Role assigned to User.

### Steps To Reproduce

Example:
create user with username: Yazıcı .
> user created.

assign role to user with UserManager

> returns identity error with the following info:
Code: InvalidUserName.
Description: Username 'Yazıcı ' is invalid, can only contain letters or digits.

### Exceptions (if any)

no exceptions

### .NET Version

6

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start with UserManager.cs and reproduce the reported flow using the username “Yazıcı ”: create the user, then assign a role through UserManager. Compare the validation performed in each operation; done means role assignment succeeds consistently for usernames accepted during creation, with regression coverage added where the existing Identity tests belong.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
authorization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.