473,426 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,426 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 6728
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

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

Similar topics

2
by: Derek White | last post by:
Ok here's the deal. We are finally getting DSL again... but our PC is in the living room... and the youngest has figured out that if he hits the right keys... he can bring up Internet Explorer....
4
by: Paul T. RONG | last post by:
Dear All, I add two new tables to the database and then the disable shift key codes don't work. These two new tables are actually created by two queries, and only these two are in the front end,...
13
by: Rich | last post by:
Hello, So I would like to disable a textbox on a vb.net form without the text getting grayed out. In vb6 I could place a textbox control on a frame control and disable the frame leaving the...
1
by: Greg Smith | last post by:
How do you hold the data in a password TextBox on a PostBack? My users don't like it if enter data into the password and password confirm Textbox and another control's PostBack clears it out. ...
6
by: =?Utf-8?B?TWljaGFlbCAwMw==?= | last post by:
I need to disable the clipboard function in Windows XP. We are having a problem with users using CTRL+C in one program, then using CTRL+V in another. Specifically, they type their password into...
0
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile...
1
by: robin1983 | last post by:
Dear All, I got stuck in simple problem, I have a two php file one for registration form and one for to check and insert into the table. The problem is that when I get any kind error in...
2
by: jd | last post by:
I have several textboxes in which the end user can enter values. When the user presses the Enter key when in any of the textboxes, or leaves that textbox, I want a routine to run (mathematical...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.