public void CanUnprotectString()
        {
            var testResult = (string)TestData.TestResults["CanProtectString"];
            var x          = _dataProtectionService.UnProtect(testResult);

            _testOutputHelper.WriteLine($"Unprotected: {x}");
            Assert.Equal("Test123", x);
        }
Ejemplo n.º 2
0
            public async Task <UserDto> Handle(GetUserByIdAndPasswordQuery request, CancellationToken cancellationToken)
            {
                var user = await _dataContext.Users.FirstOrDefaultAsync(x => x.Id == request.UserId, cancellationToken);

                if (user == null)
                {
                    return(null);
                }

                var unProtectedPassword = _protectionService.UnProtect(user.PasswordHash);

                if (unProtectedPassword != $"{user.SecurityKey}{request.Password}")
                {
                    return(null);
                }

                var projection = _dataContext.Users.Where(x => x.Id == user.Id)
                                 .Select(s => new UserDto
                {
                    Id         = s.Id,
                    Roles      = s.Roles.Select(r => r.RoleId).ToArray(),
                    ActingRole = s.Roles.Select(s => s.RoleId).First()
                });

                return(await projection.FirstAsync(cancellationToken));
            }