示例#1
0
        public async Task <IActionResult> GeneratePassword(string id)
        {
            var userModel = await _userManager.FindByIdAsync(id);

            if ((await _userManager.GetLoginsAsync(userModel)).Count != 0)
            {
                return(RedirectToAction(nameof(Index)));
            }

            var token = await _userManager.GeneratePasswordResetTokenAsync(userModel);

            var guid = Guid.NewGuid().ToString();

            _urlUrlGeneratorService.SetDerivationPrf(KeyDerivationPrf.HMACSHA256);
            var hash = _urlUrlGeneratorService.GenerateId(guid);
            await _userManager.ResetPasswordAsync(userModel, token, hash);

            NewPassword = hash;

            return(RedirectToAction(nameof(Index)));
        }