public Dashboard_Instituicao(Models.Instituicao instituicaoLogada) { InitializeComponent(); this.Text = $"Olá, {instituicaoLogada.Nome}"; this.instituicaoLogada = instituicaoLogada; }
public Models.Instituicao logaInstituicao(string login, string senha) { con = new MySqlConnection(); connection = new Connection.Connection(); con.ConnectionString = connection.getConnectionString(); string query = "SELECT * FROM instituicao WHERE Login = ?Login"; try { con.Open(); MySqlCommand command = new MySqlCommand(query, con); command.Parameters.AddWithValue("?Login", login); command.Dispose(); MySqlDataReader MySqlDR = command.ExecuteReader(); if (MySqlDR.Read()) { string senhaHash = Utils.Seguranca.generateHash(senha); string senhaSalt = MySqlDR.GetString(8); string senhaSalted = Utils.Seguranca.generateHash($"{senhaHash}{senhaSalt}"); if (senhaSalted == MySqlDR.GetString(7)) { this.instituicao = new Models.Instituicao( Convert.ToInt32(MySqlDR.GetString(0)), MySqlDR.GetString(1), MySqlDR.GetString(2), MySqlDR.GetString(3), MySqlDR.GetString(4), MySqlDR.GetString(5) ); } } } catch (Exception ex) { MessageBox.Show($"Houve um erro com o banco de dados: {ex}", "Erro BD", MessageBoxButtons.OK, MessageBoxIcon.Warning); } finally { con.Close(); } return(this.instituicao); }
private void btn_finaliza_cadastro_Click(object sender, EventArgs e) { Models.Instituicao novaInstituicao = new Models.Instituicao(); novaInstituicao.Nome = txb_nome.Text; novaInstituicao.CNPJ1 = txb_CNPJ.Text; novaInstituicao.Email = txb_email.Text; novaInstituicao.Telefone = txb_telefone.Text; novaInstituicao.Endereco = txb_endereco.Text; novaInstituicao.Login = txb_usuario.Text; novaInstituicao.Senha = txb_senha.Text; novaInstituicao.cadastraInstituicao(); this.Close(); }
private void btn_login_Click(object sender, EventArgs e) { Controllers.InstituicaoController controller = new Controllers.InstituicaoController(); Models.Instituicao instituicao = controller.logaInstituicao(txb_login.Text, txb_senha.Text); if (instituicao != null) { this.previousScreen.Hide(); this.Hide(); Paineis.Dashboard_Instituicao dashboardInstituicao = new Paineis.Dashboard_Instituicao(instituicao); dashboardInstituicao.ShowDialog(); } else { MessageBox.Show("Usuário ou senha incorretos!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public void cadastraInstituicao(Models.Instituicao novaInstituicao) { con = new MySqlConnection(); connection = new Connection.Connection(); con.ConnectionString = connection.getConnectionString(); string query = "INSERT INTO instituicao (Nome, CNPJ, Email, Telefone, Endereco, Login, Senha, SenhaSALT) VALUES (?Nome, ?CNPJ, ?Email, ?Telefone, ?Endereco, ?Login, ?Senha, ?SenhaSALT);"; Random salt = new Random(); string senhaHash = Utils.Seguranca.generateHash(novaInstituicao.Senha); string senhaSalt = Utils.Seguranca.generateHash(salt.Next(10).ToString()); string SenhaSalted = Utils.Seguranca.generateHash($"{senhaHash}{senhaSalt}"); try { con.Open(); MySqlCommand command = new MySqlCommand(query, con); command.Parameters.AddWithValue("?Nome", novaInstituicao.Nome); command.Parameters.AddWithValue("?CNPJ", novaInstituicao.CNPJ1); command.Parameters.AddWithValue("?Email", novaInstituicao.Email); command.Parameters.AddWithValue("?Telefone", novaInstituicao.Telefone); command.Parameters.AddWithValue("?Endereco", novaInstituicao.Endereco); command.Parameters.AddWithValue("?Login", novaInstituicao.Login); command.Parameters.AddWithValue("?Senha", SenhaSalted); command.Parameters.AddWithValue("?SenhaSALT", senhaSalt); command.ExecuteNonQuery(); command.Dispose(); } catch (Exception ex) { MessageBox.Show($"Houve um erro com o banco de dados: {ex}", "Erro BD", MessageBoxButtons.OK, MessageBoxIcon.Warning); } finally { con.Close(); MessageBox.Show("Instituição cadastrada com sucesso!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public Listar_Alunos_Matriculados(Models.Instituicao instituicaoLogada) { InitializeComponent(); this.instituicaoLogada = instituicaoLogada; this.preencherLista(); }