Hello Forum,
How do I make my password textbox on login form to check and accept the EXACT characters that is in the data table before logging in?
If a user types same words but different case, then it should not log in. example, if a user’s password is mErryD123 and the user types merryd123, then it should not login.
Here is my Login Code
protected void Button1_Click(object sender, EventArgs e)
{
if (txtUsername.Text != "" & txtPassword.Text != "")
{
string check = "select count(*) from [Users] where email=@email and pass=@pass";
SqlCommand com = new SqlCommand(check, con);
con.Open();
com.Parameters.AddWithValue("@email", txtUsername.Text.Trim());
com.Parameters.AddWithValue("@pass", txtPassword.Text.Trim());
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
con.Close();
if (temp == 1)
{
int user = 0;
using (SqlCommand cmd = new SqlCommand("SELECT Uid FROM Users WHERE email = @email AND pass = @pass"))
{
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@email", txtUsername.Text.Trim());
cmd.Parameters.AddWithValue("@pass", txtPassword.Text.Trim());
cmd.Connection = con;
con.Open();
user = Convert.ToInt32(cmd.ExecuteScalar());
con.Close();
}
if (user > 0)
{
Session["user"] = user;
Response.Redirect("Home.aspx");
}
}
else
{
dvMessage.Visible = true;
lblMessage.Visible = true;
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "Invalid Login Details";
txtPassword.Text = "";
txtPassword.Text = "";
// Response.Redirect(Request.Url.AbsoluteUri);
}
}
else
{
dvMessage.Visible = true;
lblMessage.Visible = true;
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "All Fields are Required";
}
}