I'm trying to login but I'm not able to do one thing.
First check that the user and password fields are filled in. So far so good. Then I verify that the password and the user are correct. And if it is correct, it will open a new form.
But I wanted to make sure that when I typed in the password field 123 (which would be a correct password) it would not open the form, but would have it execute the last if
so I would register a new password. And yes, the form would open when I log in with the new password.
I'm kind of lost and I do not know if I used ifs
and elses
correctly.
My Code:
private void btnentrar_Click(object sender, EventArgs e)
{
if ((txtLogin.Text == "") || (txtsenha.Text == ""))
{
MessageBox.Show("Digite Usuário e Senha!");
txtLogin.Focus();
}
else
{
clnlogin login = new clnlogin();
OracleDataReader objDados;
objDados = login.ListarLogin(txtLogin.Text);
if (objDados.Read())
{
login.Usuario = objDados["usuario"].ToString();
login.Senha = objDados["senha"].ToString();
if (txtsenha.Text != login.Senha)
{
MessageBox.Show(" Senha Inválida", "ocorreu um Erro ao autenticar", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtsenha.Clear();
txtsenha.Focus();
}
else
{
frmPrincipal x = new frmPrincipal();
this.Visible = false;
MessageBox.Show("Bem Vindo ao Sistema" + "," + txtLogin.Text);
x.Show();
}
}
else
{
MessageBox.Show("Usuário Incorreto!");
txtLogin.Clear();
txtsenha.Clear();
txtLogin.Focus();
}
if ((txtsenha.Text == "123"))
{
MessageBox.Show("Cadastre sua Nova Senha!");
txtsenha.Enabled = false;
txtLogin.Enabled = false;
lblnovasenha.Visible = true;
txtnovasenha.Visible = true;
btnsalvar.Visible = true;
btnCancelar.Visible = false;
btnentrar.Visible = false;
txtnovasenha.Focus();
}
}
}