Example #1
0
        public async Task <UserAutenticationDto> LoginAsync(UserAutenticationDto userDto)
        {
            try
            {
                var passwordEncrypted = _cryptStrategy.Encrypt(userDto.Password);
                var user = await _userRepository.GetUserAsync(userDto.Username, passwordEncrypted);

                if (user is null)
                {
                    userDto.AddError("Usuário e/ou senha incorretos.");
                    userDto.Password = string.Empty;
                    return(userDto);
                }

                _tokenService.GenerateToken(userDto);

                return(userDto);
            }
            catch (Exception)
            {
                userDto.AddError("Ocorreu um erro inesperado.");
                return(userDto);
            }
        }
Example #2
0
 /// <summary>
 /// Encrypts the given data using the secret.
 /// </summary>
 /// <param name="cryptoStrategy">The cryptographic strategy to use.</param>
 /// <param name="plainText">The data to encrypt.</param>
 /// <param name="optionalAssociatedData">Unencrypted data that can optionally be checked for tampering when using authenticated ciphers.</param>
 /// <returns>The encrypted data.</returns>
 internal EncryptedPacket Encrypt(ICryptoStrategy cryptoStrategy, ReadOnlySpan <byte> plainText, ReadOnlySpan <byte> optionalAssociatedData = default)
 => cryptoStrategy.Encrypt(plainText, this.Key, optionalAssociatedData);
Example #3
0
        public async Task <bool> SignInAsync(string userName, string password)
        {
            var user = await _userRepository.GetByName(userName);

            return(user != null && user.PasswordHash == _cryptoStrategy.Encrypt(password));
        }