C
C#10mo ago
Gipper

How do I take text from input element of a form and put it in AspNetUsers table properly?

I'm passing it from view to controller action through parameters, if that's relevant. This input element has to have the attribute type="password" btw (it is a password) and I would like to be able to hash the text input in it like the system does and put it into AspNetUsers and also take what's already there and unhash it. I'm doing this cause I want to give the user a way to change their current password to a new one, if there is a better way I'm open to suggestions.
5 Replies
Angius
Angius10mo ago
You do not "unhash" That's the point, hashes are one-way only Since you have AspNetUsers, you're using Identity
Jimmacle
Jimmacle10mo ago
doesn't identity already handle passwords?
Angius
Angius10mo ago
If so, use UserManager methods Yes it does UserManager has methods for login, register, change password, and so on
Jimmacle
Jimmacle10mo ago
even if you need another password-like field, you can use identity's password hasher that will use an appropriately implemented hashing algorithm for basic account management identity should handle all the basic use cases for you already
Gipper
GipperOP10mo ago
trying to inject usermanager into the relevant controller like this:
private SignInManager<IdentityUser> _signInManager;
private UserManager<IdentityUser> _userManager;

public UtilizadoresController(ApplicationDbContext context, SignInManager<IdentityUser> signInManager, UserManager<IdentityUser> userManager)
{
_context = context;
_signInManager = signInManager;
_userManager = userManager;
}
private SignInManager<IdentityUser> _signInManager;
private UserManager<IdentityUser> _userManager;

public UtilizadoresController(ApplicationDbContext context, SignInManager<IdentityUser> signInManager, UserManager<IdentityUser> userManager)
{
_context = context;
_signInManager = signInManager;
_userManager = userManager;
}
But Visual Studio doesn't recognize the UserManager<IdentityUser> type. When I change it to private Microsoft.AspNet.Identity.UserManager<IdentityUser> _userManager; I get this error: 'Microsoft.AspNetCore.Identity.IdentityUser' cannot be used as type parameter 'TUser' in the generic type or method 'UserManager<TUser>'. There is no implicit reference conversion from 'Microsoft.AspNetCore.Identity.IdentityUser' to 'Microsoft.AspNet.Identity.IUser<string>'. @jIMMACLE @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Want results from more Discord servers?
Add your server