Пример #1
0
        private void materialRaisedButton1_Click(object sender, EventArgs e)
        {
            if (txtSenha.TextLength >= 8 && txtSenha.TextLength <= 20 && txtEmail.TextLength >= 10 && txtSenha.TextLength <= 40)
            {
                crypt = new CriptDecript.CripDecript();

                cruds = new Modelo.ModeloLogin();

                cruds.email = txtEmail.Text;
                cruds.senha = crypt.Encrypt(txtSenha.Text, txtSenha.Text);

                bool Logado = cruds.ValidarLogin();

                if (Logado)
                {
                    MessageBox.Show("Usuario logado com sucesso!");

                    string usuario = cruds.getUsuario();
                    int    id      = cruds.getId();

                    this.txtEmail.Text = "";
                    this.txtSenha.Text = "";

                    frmPainel painel = new frmPainel(usuario, cruds.email, id);
                    painel.Show();
                    this.Hide();
                }
                else
                {
                    lblMessage.Text = "Nome de usuario/senha incorretos.";
                }
            }
            else
            {
                lblMessage.Text = "Informe um usuario válido!";
            }
        }
Пример #2
0
        private void btnRegistrar_Click(object sender, EventArgs e)
        {
            if (txtEmail.TextLength >= 10)
            {
                if (txtEmail.TextLength <= 40)
                {
                    if (txtSenha.TextLength >= 8)
                    {
                        if (txtSenha.TextLength <= 20)
                        {
                            if (txtUsuario.TextLength >= 5)
                            {
                                if (txtUsuario.TextLength <= 25)
                                {
                                    cript = new CriptDecript.CripDecript();
                                    cruds = new Modelo.ModeloLogin();

                                    cruds.email   = txtEmail.Text;
                                    cruds.senha   = cript.Encrypt(txtSenha.Text, txtSenha.Text);
                                    cruds.usuario = txtUsuario.Text;

                                    bool criado = cruds.RegistrarUsuario();
                                    if (criado)
                                    {
                                        MessageBox.Show("Usuario criado com sucesso!");
                                        this.Hide();
                                    }
                                    else
                                    {
                                        vermelho("O email/usuario já está em uso!");
                                    }
                                }
                                else
                                {
                                    vermelho("O nome de Usuario não deve ultrapassar 25 caracteres.");
                                }
                            }
                            else
                            {
                                vermelho("O nome de usuario deve ter no minimo 5 carcteres.");
                            }
                        }
                        else
                        {
                            vermelho("A senha não deve ultrapassar 20 caracteres.");
                        }
                    }
                    else
                    {
                        vermelho("A senha deve ter no minimo 8 caracteres.");
                    }
                }
                else
                {
                    vermelho("O Email não deve ultrapassar 40 caracteres.");
                }
            }
            else
            {
                vermelho("O Email deve ter no minimo 10 caracteres.");
            }
        }
        private void dtvDados_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 6)
            {
                this._senhaAES = txtSenhaAES.Text;

                if (this._senhaAES.Length >= 8)
                {
                    int                      linha2 = dtvDados.CurrentRow.Index;
                    DataGridViewRow          linha  = dtvDados.CurrentRow;
                    CriptDecript.CripDecript cripto = new CriptDecript.CripDecript();

                    try {
                        linha.Cells[1].Value = cripto.Encrypt(this._senhaAES, linha.Cells[1].Value.ToString());
                        linha.Cells[2].Value = cripto.Encrypt(this._senhaAES, linha.Cells[2].Value.ToString());
                        linha.Cells[3].Value = cripto.Encrypt(this._senhaAES, linha.Cells[3].Value.ToString());
                        linha.Cells[4].Value = cripto.Encrypt(this._senhaAES, linha.Cells[4].Value.ToString());
                        linha.Cells[5].Value = cripto.Encrypt(this._senhaAES, linha.Cells[5].Value.ToString());

                        CarregarNasTextBox();
                        AtualizarLinha(linha2);

                        verde("Dados criptografados com sucesso!");
                    } catch (CriptDecript.FormatoTextoInvalido) {
                        MessageBox.Show("Formato de texto inválido! Tente novamente!");
                        vermelho("Erro de formato de texto.");
                    }
                }
                else
                {
                    vermelho("A senha deve conter no minimo 8 caracteres.");
                    txtSenhaAES.Focus();
                }
            }
            else if (e.ColumnIndex == 7)
            {
                this._senhaAES = txtSenhaAES.Text;

                if (this._senhaAES.Length >= 8)
                {
                    int                      linha2  = dtvDados.CurrentRow.Index;
                    DataGridViewRow          linha   = dtvDados.CurrentRow;
                    CriptDecript.CripDecript decrypt = new CriptDecript.CripDecript();

                    try {
                        linha.Cells[1].Value = decrypt.Decrypt(this._senhaAES, linha.Cells[1].Value.ToString());
                        linha.Cells[2].Value = decrypt.Decrypt(this._senhaAES, linha.Cells[2].Value.ToString());
                        linha.Cells[3].Value = decrypt.Decrypt(this._senhaAES, linha.Cells[3].Value.ToString());
                        linha.Cells[4].Value = decrypt.Decrypt(this._senhaAES, linha.Cells[4].Value.ToString());
                        linha.Cells[5].Value = decrypt.Decrypt(this._senhaAES, linha.Cells[5].Value.ToString());

                        CarregarNasTextBox();

                        verde("Dados decriptografados com sucesso!");
                    } catch (CriptDecript.FormatoTextoInvalido) {
                        MessageBox.Show("Formato de texto inválido! Tente novamente!");

                        vermelho("Erro de formato de texto.");
                    } catch (CriptDecript.SenhaIncorreta) {
                        MessageBox.Show("Senha incorreta!");

                        vermelho("Senha de decrypt incorreta.");
                    }
                }
                else
                {
                    vermelho("Senha inválida. Minimo de 8 caracteres.");
                    txtSenhaAES.Focus();
                }
            }
        }