private void btnLogar_Click(object sender, EventArgs e) { ConexaoDb conexaoDb = new ConexaoDb(); HashPwd hashPwd = new HashPwd(); ModificaUser mdUser = new ModificaUser(); Util util = new Util(); string id; try { string sql = ""; if (String.IsNullOrEmpty(txtLogin.Text) || String.IsNullOrEmpty(txtSenha.Text)) { MessageBox.Show("Não é possivel logar com campos vazios"); return; } if (!util.verificaEmail(txtLogin.Text)) { MessageBox.Show("Email Inválido!"); return; } if (confereCaracteresPerigosos(txtLogin.Text)) { string hashSenha = hashPwd.HashValue(txtSenha.Text); sql = "SELECT * FROM Crud_User WHERE " + "email = '" + txtLogin.Text + "' and " + "senha = '" + hashSenha + "'"; if (conexaoDb.verificaUsuario(sql)) { conexaoDb.ConexaoDbOpen(); sql = "SELECT ID FROM Crud_User WHERE " + "email = '" + txtLogin.Text + "' and " + "senha = '" + hashSenha + "'"; id = conexaoDb.resultLabel(sql); MessageBox.Show("Login bem sucedido"); mdUser.verificaPermissaoUser(txtLogin.Text, hashSenha, id); mdUser.Closed += (s, args) => this.Close(); mdUser.Show(); Hide(); } else { MessageBox.Show("Email ou senha errados ou este usuario não foi cadastrado"); } } } catch (Exception ex) { MessageBox.Show("Ocorreu uma falha ao logar"); } finally { conexaoDb.FecharConexao(); } }
private void btnSalvar_Click(object sender, EventArgs e) { ConexaoDb conexaodb = new ConexaoDb(); HashPwd hashPwd = new HashPwd(); Util util = new Util(); string verificaNumero = "^[0-9]"; try { string sql = ""; string recebeSalario = txtSalario.Text; recebeSalario = recebeSalario.Replace(",", "."); char charac = recebeSalario.ToCharArray()[0]; int verificaSequencia = charac * 11; if (verificaSequencia.ToString() == txtSalario.Text) { MessageBox.Show("Essa sequencia do campo de salário não é permitida"); } if (String.IsNullOrEmpty(txtEmail.Text) || String.IsNullOrEmpty(txtName.Text) || String.IsNullOrEmpty(txtSenha.Text)) { MessageBox.Show("Algum campo ficou vazio, não sera possivel efetuar o cadastro!"); return; } if (!util.verificaEmail(txtEmail.Text)) { MessageBox.Show("Email Inválido!"); return; } if (!Regex.IsMatch(txtSalario.Text, verificaNumero)) { MessageBox.Show("Só é permitido numeros no campo de salário"); return; } if (confereCaracteresPerigosos(txtEmail.Text)) { if (confereCaracteresPerigosos(txtName.Text)) { string hashSenha = hashPwd.HashValue(txtSenha.Text); sql = "INSERT INTO Crud_User(nome, email, senha, salario) VALUES ( " + "'" + txtName.Text + "', " + "'" + txtEmail.Text + "', " + "'" + hashSenha + "', " + "" + recebeSalario + "" + ")"; conexaodb.ExecutaQuery(sql); } else { return; } } else { return; } MessageBox.Show("Cadastro efetuado com sucesso!"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } finally { LimparDados(); } }