0
I’m trying to log in, but I’m not able to do one thing.
I first check that the user and password fields are filled in. So far so good. I then check that the password and the user are correct. And in case you’re correct he’ll open a new form.
However, I would like to make sure that when I type in the password field 123 (which would be a correct password) it does not open the form but runs the last if
for me to register a new password. And then yes, the form would open when I logged in with the new password.
I’m kind of lost and I don’t know if I used the ifs
and the 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();
}
}
}
Just put the if of the password at the beginning of the first Else.
– Douglas