Exemple #1
0
 public int Adicionar(UsuarioNovo usuario)
 {
     try
     {
         using (var conexao = new SQLiteConnection(System.IO.Path.Combine(pasta, "Usuario.db")))
         {
             return(conexao.Insert(usuario));
         }
     }
     catch
     {
         throw new ArgumentException("Erro ao cadastrar.");
     }
 }
Exemple #2
0
        private static void HashSenha(UsuarioNovo usuario, string senha)
        {
            Guid saltGuid = Guid.NewGuid();

            byte[] saltBytes = saltGuid.ToByteArray();

            // Derivando uma chave de 256bits utilizanod HMACSHA1 e dez mil iterações
            string hashSenha = Convert.ToBase64String(KeyDerivation.Pbkdf2(
                                                          password: senha,
                                                          salt: saltBytes,
                                                          prf: KeyDerivationPrf.HMACSHA256,
                                                          iterationCount: 10000,
                                                          numBytesRequested: 256 / 8));

            usuario.SenhaHash = hashSenha;
            usuario.Salt      = saltGuid.ToString();
        }
Exemple #3
0
        public static void Inserir(UsuarioNovo usuario)
        {
            var apuracao = new List <Usuario>();

            using (var conexao = new NpgsqlConnection(Configuracaoes.ConnectionString))
            {
                conexao.Open();
                using (var comando = new NpgsqlCommand(queryInserir, conexao))
                {
                    comando.Parameters.AddWithValue("nome", usuario.Nome);
                    comando.Parameters.AddWithValue("login", usuario.Login);
                    comando.Parameters.AddWithValue("auditor", usuario.Auditor);
                    comando.Parameters.AddWithValue("senhahash", usuario.SenhaHash);
                    comando.Parameters.AddWithValue("salt", usuario.Salt);
                    var reader = comando.ExecuteNonQuery();
                }
            }
        }
 public bool Login(string usuario, string senha)
 {
     try
     {
         using (var conexao = new SQLiteConnection(System.IO.Path.Combine(pasta, "Usuario.db")))
         {
             UsuarioNovo resultado = conexao.FindWithQuery <UsuarioNovo>("SELECT * FROM UsuarioNovo Where Usuario=? AND Senha=?", usuario, senha);
             if (resultado != null)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (SQLiteException ex)
     {
         throw new System.Exception(ex.Message);
     }
 }
Exemple #5
0
        public static void Inserir()
        {
            while (true)
            {
                Console.Clear();
                Console.WriteLine("LOGIN:"******"JÁ EXISTE UM USUÁRIO CADASTRADO COM ESTE LOGIN. PRESSIONE QUALQUER TECLA PARA VOLTAR.");
                    Console.ReadKey(true);
                    break;
                }

                Console.WriteLine("NOME:");
                var nomeInput = Console.ReadLine().Trim();
                Console.WriteLine("USUÁRIO AUDITOR? (S/N)");
                bool auditor;
                while (true)
                {
                    var auditorInput = Console.ReadKey(true);
                    if (auditorInput.Key == ConsoleKey.S)
                    {
                        auditor = true;
                        Console.WriteLine("S");
                        break;
                    }
                    if (auditorInput.Key == ConsoleKey.N)
                    {
                        auditor = false;
                        Console.WriteLine("N");
                        break;
                    }
                }

                string senhaInput;

                while (true)
                {
                    Console.WriteLine("SENHA:");
                    senhaInput = Aplicacao.GetConsolePassword();
                    Console.WriteLine("CONFIRMAÇÃO DA SENHA:");
                    var senhaConfirmacaoInput = Aplicacao.GetConsolePassword();
                    if (!senhaInput.Equals(senhaConfirmacaoInput))
                    {
                        Console.WriteLine("A SENHA E SUA CONFIRMAÇÃO DEVEM SER IGUAIS. PRESSIONE QUALQUER TECLA PARA TENTAR NOVAMENTE.");
                        Console.ReadKey(true);
                        continue;
                    }
                    break;
                }

                if (string.IsNullOrWhiteSpace(loginInput) ||
                    string.IsNullOrWhiteSpace(nomeInput) ||
                    string.IsNullOrWhiteSpace(senhaInput))
                {
                    Console.WriteLine("TODAS AS INFORMAÇÕES SÃO OBRIGATÓRIAS. PRESSIONE QUALQUER TECLA PARA VOLTAR.");
                    Console.ReadKey(true);
                    break;
                }

                var novoUsuario = new UsuarioNovo(nomeInput, loginInput, auditor);
                HashSenha(novoUsuario, senhaInput);
                UsuarioService.Inserir(novoUsuario);
                Console.WriteLine("");
                Console.WriteLine("PRESSIONE QUALQUER TECLA PARA VOLTAR.");
                Console.ReadKey(true);
                break;
            }
        }