Username '' is invalid, can only contain letters or digits. Login. Identity.

Volk Volk 571 Reputation points
2022-07-04T09:08:59.843+00:00

Hello!

I am writing a Login Form for a site on the MVC Net Core 6 Web App, but I can't find where I can fix the UserName verification error. It should be unique for me, as well as Email. I just need to pass the correct UserName and Email verification and I don't understand what the error is and where I can see (or set my own) regular expressions for these checks.

I searched for an answer on various forums and in the project itself - did not find anything.

Thank you!

217323-login.png

217341-login.png217342-login.png217229-login.png217230-login.png

217483-login.png

Need to save in Table

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,177 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Volk Volk 571 Reputation points
    2022-07-05T07:16:49.6+00:00
    @model VolkGam.Models.ApplicationUser  
        @{  
            ViewData["Title"] = "Create";  
        }  
        <br />  
          
        <h2 class="text-info">Registration</h2>  
          
        <form asp-action="Create" method="post" id="user-form" enctype="multipart/form-data">  
            <div class="p-4 rounded border">  
                <div asp-validation-summary="ModelOnly" class="text-danger">  
          
                </div>  
                <h3>@ViewBag.message</h3>  
          
                <div class="form-group row">  
                    <div class="col-2">  
                        <label asp-for="Login">Login*</label>  
                    </div>  
                    <div class="col-5">                  
                        <input asp-for="Login" class="form-control" exp/>  
                    </div>  
                    <span asp-validation-for="Login" class="text-danger">Required. Symbols: 3-15. Letters: a-zA-Z. Numbers: 0-9.</span>             
                </div>  
          
                <div class="form-group row">  
                    <div class="col-2">  
                        <label asp-for="UserName">Email*</label>  
                    </div>  
                    <div class="col-5">                  
                        <input asp-for="UserName" class="form-control"/>  
                    </div>  
                    <span asp-validation-for="UserName" class="text-danger">Required.</span>  
                </div>  
          
                <br></br>  
          
                <div class="form-group row">  
                    <div class="col-2">  
                        <label asp-for="PasswordHash">Password*</label>  
                    </div>  
                    <div class="col-5">  
                        <form action="">  
                        <div class="form-item">  
                            <input asp-for="PasswordHash" type="password" class="form-control form-control-lg" id="password" placeholder="password"/>  
                            <i class="fas fa-eye" id="eye"></i>  
                        </div>                          
                        </form>  
                    </div>  
                    <span asp-validation-for="PasswordHash" class="text-danger">Required. Min symbols: 8. Letters: a-zA-Z. At least one: 0-9. At least one special symbols.</span>  
                </div>  
          
                <br></br>  
          
                <div class="form-group row">  
                    <div class="col-2">                  
                        <label asp-for="FirstName">First name*</label>  
                    </div>  
                    <div class="col-5">  
                        <input asp-for="FirstName" class="form-control"/>  
                    </div>  
                    <span asp-validation-for="FirstName" class="text-danger">Required.</span>  
                </div>  
          
                <div class="form-group row">  
                    <div class="col-2">  
                        <label asp-for="LastName">Last name*</label>  
                    </div>  
                    <div class="col-5">  
                        <input asp-for="LastName" class="form-control" />  
                    </div>  
                    <span asp-validation-for="LastName" class="text-danger">Required</span>  
                </div>  
          
                <br></br>  
          
                <div class="form-group">  
                    <a asp-area="Customer" asp-action="Index" asp-controller="Home" class="button large">Home</a>  
                    <input type="submit" class="button large" value="Register" />  
                </div>  
            </div>  
        </form>  
    

    217567-z-3.png

    217624-z-4.png

    I found:

    Cannot access a disposed object Object name: 'UserManager`1'
    cannot-access-a-disposed-object-object-name-usermanager1

    ---
    If another object has a reference to userManager and that object is disposed, it might be disposing userManager along with it. Another possibility is userManager requires some type of initialization which hasn't been done yet, and its properties throw a misleading disposed exception (this is common with winform controls).

    ---

    But I don't delete the login form during the execution of the method: public async Task<IActionResult> Create(Application User user)

    Strange. What could be the problem?

    0 comments No comments

  2. Volk Volk 571 Reputation points
    2022-07-05T11:24:52.14+00:00

    The problem is solved by the fact that I just returned the UserName and marked it as an Email input. Apparently, it's better not to touch the UserName or try to write something else into it. The logic of Identity is designed in such a way that it is easier to add another necessary column to the table and work with it. But what is the point of duplicating UserName and Email in the table, I did not understand. The question is closed. And the problem with the error ObjectDisposedExeption will be moved to another thread.

    0 comments No comments