NormalizedUserName VS Username in DotNet Core

I am trying to create a custom implementation of IUserLoginStore for MongoDB, and I noticed when using

UserManager<ApplicationUser> 

using method

  var userResult = await _userManager.CreateAsync(user); 

he goes through implementation

 GetUserNameAsync FindByNameAsync SetNormalizedUserNameAsync GetUserIdAsync 

I would like to clarify two questions:

  • What is the purpose of having NormalizedUsername and UserName? the only difference is that I could notice id that normalizedUserName is uppercase.

  • I use my implementation only to store users from an external input (Google plus), is there a way in which I can omit the username and NormilizedUserName, since I mainly use email in these three fields, I feel like I'm duplicating data, and that makes no sense to me.

any recommendations?

+3
source share
2 answers

1) Normalization stops people registering usernames that differ only in letter.

2) No - these fields are part of the underlying data model.

+5
source
  1. Yes you can (if you want):
    • FindByNameAsync should search by u.Name case insensitive (do you trust your database settings?)
    • GetNormalizedUserNameAsync should return user.Name.ToUpperCase ()
    • SetNormalizedUserNameAsync should not do anything

Please note that 2.1 can skip any index in the name column in the database and damage the performance of your application (check your database again). Or cause the execution of the "client side" (and again dramatically degrade performance). Depending on your implementation.

I use this "minimized" User class only on internal corporate systems that use only a specific OAuth provider and only accept users from a specified domain (Google Apps). These systems do not search by username, and I safely throw a NotImplementedException in many methods.

+4
source

Source: https://habr.com/ru/post/1013673/


All Articles