private void btnCadastro_Click(object sender, EventArgs e) { try { String str = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\LojaChingLing-master\\DbLoja.mdf;Integrated Security=True;Connect Timeout=30"; SqlConnection con = new SqlConnection(str); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "InserirUsuario"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@nome", txtNome.Text); cmd.Parameters.AddWithValue("@login", txtLogin.Text); cmd.Parameters.AddWithValue("@senha", txtSenha.Text = b.Base64Encode(txtSenha.Text)); //txtSenha.Text = b.Base64Encode(txtSenha.Text); con.Open(); cmd.ExecuteNonQuery(); CarregaDgvUsuario(); MessageBox.Show("Registro inserido com sucesso!", "Cadastro", MessageBoxButtons.OK); con.Close(); txtId.Text = ""; txtNome.Text = ""; txtLogin.Text = ""; txtSenha.Text = ""; } catch (Exception er) { MessageBox.Show(er.Message); } }
private void btnCadastro_Click(object sender, EventArgs e) { try { SqlConnection con = Conexao.obterConexao(); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "InserirUsuario"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@nome", txtNome.Text); cmd.Parameters.AddWithValue("@login", txtLogin.Text); //Pego o valor o txtSenha e codifico ela. txtSenha.Text = b.Base64Encode(txtSenha.Text); //Crio uma nova varialvel e atribuo o txtSenha a ela. string criptografada = txtSenha.Text; //Passo para o parametro gravar a senha decodificada. cmd.Parameters.AddWithValue("@senha", criptografada); Conexao.obterConexao(); cmd.ExecuteNonQuery(); CarregaDgvUsuario(); MessageBox.Show("Registro inserido com sucesso!", "Cadastro", MessageBoxButtons.OK); Conexao.fecharConexao(); txtId.Text = ""; txtNome.Text = ""; txtLogin.Text = ""; txtSenha.Text = ""; } catch (Exception er) { MessageBox.Show(er.Message); } }
private void btnLogar_Click(object sender, EventArgs e) { SqlConnection con = Conexao.obterConexao(); string usu = "select login,senha from usuario where login=@login and senha=@senha"; SqlCommand cmd = new SqlCommand(usu, con); cmd.Parameters.AddWithValue("@login", SqlDbType.NChar).Value = txtLogin.Text.Trim(); txtSenha.Text = b.Base64Encode(txtSenha.Text); string criptografada = txtSenha.Text; cmd.Parameters.AddWithValue("@senha", SqlDbType.NChar).Value = criptografada; Conexao.obterConexao(); cmd.CommandType = CommandType.Text; SqlDataReader usuario = cmd.ExecuteReader(); if (usuario.HasRows) { this.Hide(); FrmPrincipal pri = new FrmPrincipal(); pri.Show(); usuario.Close(); Conexao.fecharConexao(); } else { MessageBox.Show("Login ou senha incorretos! Tente novamente!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); txtLogin.Text = ""; txtSenha.Text = ""; usuario.Close(); con.Close(); } }
private void btnLogin_Click(object sender, EventArgs e) { String str = "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\LojaChingLing-master\\DbLoja.mdf;Integrated Security=True;Connect Timeout=30"; string usu = "select login,senha from usuario where login=@login and senha=@senha"; SqlConnection con = new SqlConnection(str); SqlCommand cmd = new SqlCommand(usu, con); cmd.Parameters.AddWithValue("@login", SqlDbType.NChar).Value = txtLogin.Text.Trim(); cmd.Parameters.AddWithValue("@senha", SqlDbType.NChar).Value = txtSenha.Text = b.Base64Encode(txtSenha.Text.Trim()); con.Open(); cmd.CommandType = CommandType.Text; SqlDataReader usuario = cmd.ExecuteReader(); if (usuario.HasRows) { this.Hide(); FrmPrincipal pri = new FrmPrincipal(); pri.Show(); con.Close(); } else { MessageBox.Show("Login ou senha incorretos! Tente novamente!", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); txtLogin.Text = ""; txtSenha.Text = ""; con.Close(); } }