472,145 Members | 1,489 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,145 software developers and data experts.

Disable TextBox When Enter worng Password 3 Times (C#)

29
hello

i have a program in c#

Expand|Select|Wrap|Line Numbers
  1. protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.         Datareader1 = MyCom1.ExecuteReader();
  4.         if (Datareader1.Read())
  5.         {
  6.             Datareader1.Close();
  7.             DataReader = MyCom.ExecuteReader();
  8.             if (DataReader.Read())
  9.             {
  10.                 Response.Redirect("Default.aspx?uname=" + TextBox1.Text);
  11.             }
  12.  
  13.             else
  14.             {
  15.                 MessageBox.Show("Password Is Wrong", "Wrong Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
  16.             }
  17.  
  18.         }
  19.         else
  20.         {
  21.             MessageBox.Show("UserName Is Not Found");
  22.  
  23.         }
  24.     }
I want to Disable The Password's TextBox If the User Enter A wrong password 3 times

i tried to do this with for but it didn't work

any help plz ?!
Mar 7 '07 #1
10 6615
radcaesar
759 Expert 512MB
Have a session variable and increment it when the password is wrong.

Disable the txtPassword (TextBox) when the session variable ==3

:)
Mar 7 '07 #2
MCPD
29
please can u explain more

becuase i am new and not professional

what mean session variable
Mar 7 '07 #3
MCPD
29
if u mean

Expand|Select|Wrap|Line Numbers
  1. Session ["abc"] =0;
i know that the session variable cant be increased

i cant do this

Expand|Select|Wrap|Line Numbers
  1. Session["abc"]+=1;
Mar 7 '07 #4
radcaesar
759 Expert 512MB
A Session variable retains the value until its destroyed or the browser is closed.

Refer ASP .NET tutors for more informations.

:)
Mar 7 '07 #5
MCPD
29
if u mean

Expand|Select|Wrap|Line Numbers
  1. Session ["abc"] =0;
i know that the session variable cant be increased

i cant do this

Expand|Select|Wrap|Line Numbers
  1. Session["abc"]+=1;
please read this
Mar 7 '07 #6
radcaesar
759 Expert 512MB
But i can do that

Session["LoginAttempt"] = ((int) Session["LoginAttempt"]) + 1;
return (int) Session["LoginAttempt"];

Right ?????

:)
Mar 7 '07 #7
MCPD
29
it doesn't work man

i write this

Expand|Select|Wrap|Line Numbers
  1. protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.         Session["LoginAttempt"] = 0;
  4.         Datareader1 = MyCom1.ExecuteReader();
  5.         if (((int)Session["LoginAttempt"]) != 3)
  6.         {
  7.             if (Datareader1.Read())
  8.             {
  9.                 Datareader1.Close();
  10.                 DataReader = MyCom.ExecuteReader();
  11.                 if (DataReader.Read())
  12.                 {
  13.                     Response.Redirect("Default.aspx?uname=" + TextBox1.Text);
  14.                 }
  15.  
  16.                 else
  17.                 {
  18.                     MessageBox.Show("Password Is Wrong", "Wrong Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
  19.                     Session["LoginAttempt"] = ((int)Session["LoginAttempt"]) + 1;
  20.                 }
  21.  
  22.             }
  23.             else
  24.             {
  25.                 MessageBox.Show("UserName Is Not Found");
  26.  
  27.             }
  28.         }
  29.         else
  30.         {
  31.             MessageBox.Show("You Login Faild");
  32.             TextBox2.Enabled = false;
  33.         }
  34.         }
  35.  
  36.     }
Mar 7 '07 #8
radcaesar
759 Expert 512MB
Debug this code line by line. It never works, if you approach like this.

What that mean
if (Datareader1.Read()) ?

Debug and check whether it searches for correct username and password.

:)

it doesn't work man

i write this



Expand|Select|Wrap|Line Numbers
  1. protected void Button1_Click(object sender, EventArgs e)
  2.     {
  3.         Session["LoginAttempt"] = 0;
  4.         Datareader1 = MyCom1.ExecuteReader();
  5.         if (((int)Session["LoginAttempt"]) != 3)
  6.         {
  7.             if (Datareader1.Read())
  8.             {
  9.                 Datareader1.Close();
  10.                 DataReader = MyCom.ExecuteReader();
  11.                 if (DataReader.Read())
  12.                 {
  13.                     Response.Redirect("Default.aspx?uname=" + TextBox1.Text);
  14.                 }
  15.  
  16.                 else
  17.                 {
  18.                     MessageBox.Show("Password Is Wrong", "Wrong Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
  19.                     Session["LoginAttempt"] = ((int)Session["LoginAttempt"]) + 1;
  20.                 }
  21.  
  22.             }
  23.             else
  24.             {
  25.                 MessageBox.Show("UserName Is Not Found");
  26.  
  27.             }
  28.         }
  29.         else
  30.         {
  31.             MessageBox.Show("You Login Faild");
  32.             TextBox2.Enabled = false;
  33.         }
  34.         }
  35.  
  36.     }
Mar 7 '07 #9
MCPD
29
DataReader.Read() thats my datareader
and it check if the command is return something from the sql
and this is what containt the datareader1

Datareader1 = MyCom1.ExecuteReader();

And MyCom1 Is

MyCom1 = new SqlCommand("select * from Users where UserName='" + TextBox1.Text + "'", MyCon);
Mar 7 '07 #10
MCPD
29
By The Way I asked alot of people who know c# very well

and no body success to resolve this

its too strange :(
Mar 7 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Derek White | last post: by
1 post views Thread by Greg Smith | last post: by
6 posts views Thread by =?Utf-8?B?TWljaGFlbCAwMw==?= | last post: by
2 posts views Thread by jd | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.