private void btnLogin_Click(object sender, EventArgs e) { AccountsDAO accountsDao = new AccountsDAO(); DataTable table = accountsDao.Select_All(); if (table.Rows.Count == 0) { accountsDao.insert(new Account() { Username = CryptMngr.Encrypt("admin"), Password = CryptMngr.Encrypt("admin"), Account_type = (int)Account.account_types.admin }); table = accountsDao.Select_All(); } bool didFind = false; DataRow account = table.NewRow(); foreach (DataRow item in table.Rows) { if (CryptMngr.Decrypt(item["username"].ToString()) == txtUsername.Text && CryptMngr.Decrypt(item["password"].ToString()) == txtPassword.Text) { account = item; didFind = true; break; } } if (didFind) { LogintoIt(account); } else { MessageBox.Show("As credenciais inseridas não correspondem a nenhuma conta", "Erro de Login"); txtPassword.Clear(); txtUsername.Clear(); } }
/// <summary> /// Cadastra as informações dadas no banco de dados /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnCadNewUser_Click(object sender, EventArgs e) { AccountsDAO accounts = new AccountsDAO(); accounts.insert(new Account() { Username = CryptMngr.Encrypt(txtCadUsername.Text), Password = CryptMngr.Encrypt(txtCadPassword.Text), Account_type = cmbCadAccType.SelectedIndex }); //cadastra a parte do cliente if (cmbCadAccType.SelectedIndex == 0) { ClienteDAO cliente = new ClienteDAO(); cliente.insert(new Cliente() { IdAccount = int.Parse( accounts.loadTable("Select id_accounts from accounts where username = '******'").Rows[0]["id_accounts"].ToString()), Email = CryptMngr.Encrypt(txtCadCliEmail.Text) }); } }