PasswordHasher<TUser> 对 TUser 没有任何作用,为什么那个通用参数在那里?

PasswordHasher<TUser> does nothing with TUser, why is that generic parameter there?

这是密码哈希器的来源。 https://github.com/dotnet/AspNetCore/blob/master/src/Identity/Extensions.Core/src/PasswordHasher.cs

您可以清楚地看到通用类型 TUser 仅在 2 个 public 方法中使用,并且在这些方法中从未使用过参数本身。

为什么 class 会像这样泛化?

有趣的问题。似乎出于可扩展性目的。来自 this article 的好评:

It is useful for cases when you implement your own IPasswordHasher. For example you may need to verify the password and you need the salt for the user if you salted your users password in your custom hasher. If the the user wasn't provided you would need to get the user via a second trip to your user store if the only gave you the user email or id so could be able to hash passed in password agianst the sale for comparison.