Hi
i am currently creating a login screen for my project.The logical error with this code is that it does not display the message "invalid password" although i have written a code for it.Can anyone please tell me whats wrong with this code.Thanks in advance
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace GOGREEN
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
label1.Left = label1.Left - 4;
if (label1.Left < 0)
{
label1.Left = 400;
}
}
private void button2_Click(object sender, EventArgs e)
{
Close();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
MessageBox.Show("Please enter your user name");
}
if (textBox2.Text == "")
{
MessageBox.Show("Please enter a relevent password");
}
Login l = new Login();
l.Focus();
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=MIRFATH-PC;Initial Catalog=GOGREEN;Integrated Security=True";
progressBar1.Value = 10;
try
{
con.Open();
progressBar1.Value = 30;
}
catch (Exception e1)
{
MessageBox.Show(e1.Message);
}
SqlCommand com = new SqlCommand("Select * from Login_File where UserName=@una and Password=@p", con);
com.Parameters.AddWithValue("@una", textBox1.Text);
com.Parameters.AddWithValue("@p", textBox2.Text);
SqlDataReader dr = com.ExecuteReader();
progressBar1.Value = 50;
try
{
while (dr.Read())
{
if (dr.HasRows == true)
{
progressBar1.Value = 100;
MessageBox.Show("Welcome to GOGREEN SALES ORDER PROCESSING SYSTEM! You have sucessfully loged in!");
Main_Menu m = new Main_Menu();
m.Show();
}
else
{
MessageBox.Show("Access Denied", "Login Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
catch (Exception)
{
if (dr.HasRows == false)
{
MessageBox.Show("Access Denied", "Login Information", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
con.Close();
}
}
}
Additional Information
User Name:Mirfath
Password:m123
the above information is retrieved from the database