PasswordHashingService hashingService; [Allowanonymous] [HttpPost]…
- User
PasswordHashingService _hashingService; [Allowanonymous] [HttpPost] [ValidateAntiForgeryToken] public async Task Register(RegisterInputModel model) {
var existingUser = _UserRepo.getUser(model.Email); if (existingUser = = null) _userRepo.CreateUser (model.Email, model.Password); return View();} use hashingservice in registration to encrypt password sent by user
- Assistant
To use the
PasswordHashingService(_hashingService) in your registration process to securely hash the user's password before storing it, you can modify yourRegisteraction method as follows:csharp[AllowAnonymous] [HttpPost] [ValidateAntiForgeryToken] public async Task<ActionResult> Register(RegisterInputModel model) { var existingUser = _userRepo.GetUser(model.Email); if (existingUser == null) { // Hash the user's password using the _hashingService var hashedPassword = _hashingService.HashPassword(model.Password); // Create the user with the hashed password _userRepo.CreateUser(model.Email, hashedPassword); } return View(); }