示例#1
0
        /// <inheritdoc />
        public async Task <ForgotPasswordResult> StartForgotPasswordProcess(User user, bool isInNetwork)
        {
            byte[] bytes = new byte[4];
            RandomNumberGenerator.Fill(bytes);
            string pin = BitConverter.ToString(bytes);

            DateTime expireTime           = DateTime.UtcNow.AddMinutes(30);
            string   filePath             = _passwordResetFileBase + user.Id + ".json";
            SerializablePasswordReset spr = new SerializablePasswordReset
            {
                ExpirationDate = expireTime,
                Pin            = pin,
                PinFile        = filePath,
                UserName       = user.Username
            };

            await using (FileStream fileStream = AsyncFile.OpenWrite(filePath))
            {
                await JsonSerializer.SerializeAsync(fileStream, spr).ConfigureAwait(false);
            }

            user.EasyPassword = pin;

            return(new ForgotPasswordResult
            {
                Action = ForgotPasswordAction.PinCode,
                PinExpirationDate = expireTime,
                PinFile = filePath
            });
        }
        public async Task <ForgotPasswordResult> StartForgotPasswordProcess(User user, bool isInNetwork)
        {
            string pin;

            using (var cryptoRandom = RandomNumberGenerator.Create())
            {
                byte[] bytes = new byte[4];
                cryptoRandom.GetBytes(bytes);
                pin = BitConverter.ToString(bytes);
            }

            DateTime expireTime           = DateTime.UtcNow.AddMinutes(30);
            string   filePath             = _passwordResetFileBase + user.Id + ".json";
            SerializablePasswordReset spr = new SerializablePasswordReset
            {
                ExpirationDate = expireTime,
                Pin            = pin,
                PinFile        = filePath,
                UserName       = user.Username
            };

            await using (FileStream fileStream = File.OpenWrite(filePath))
            {
                _jsonSerializer.SerializeToStream(spr, fileStream);
                await fileStream.FlushAsync().ConfigureAwait(false);
            }

            user.EasyPassword = pin;
            await _userManager.UpdateUserAsync(user).ConfigureAwait(false);

            return(new ForgotPasswordResult
            {
                Action = ForgotPasswordAction.PinCode,
                PinExpirationDate = expireTime,
            });
        }