473,405 Members | 2,294 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,405 software developers and data experts.

check this coding once which for displaying captcha image

hai,
i have written this below code for displaying captcha image whenever i entered incorrect uname,password in login page.
for that i disable the controls of captcha like textbox,labels,button and image control in source code of designing part.
and i enable those controls in an if condition which display captcha.
but if i entered correct information which is in database
it shouldn't navigate to the corresponding page
and also if entered incorrect data it shouldn't displys captcha.
whats problem behind this coding?
check it
and give correct code for this one if any.


namespace CaptchaImage
{
public partial class DefaultImage : System.Web.UI.Page
{
static int a = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)

// Create a random code and store it in the Session object.
this.Session["CaptchaImageText"] = GenerateRandomCode();

else
{
// On a postback, check the user input.
if (this.CodeNumberTextBox.Text ==
this.Session["CaptchaImageText"].ToString())
{
// Display an informational message.
this.MessageLabel.CssClass = "info";
this.MessageLabel.Text = "Correct!";
}
else
{
//Display an error message.
this.MessageLabel.CssClass = "error";
this.MessageLabel.Text = "ERROR: Incorrect, try again.";

// Clear the input and create a new random code.
this.CodeNumberTextBox.Text = "";
this.Session["CaptchaImageText"] = GenerateRandomCode();
}
}

}
private Random random = new Random();
private string GenerateRandomCode()
{
string s = "";
for (int i = 0; i < 6; i++)
s = String.Concat(s, this.random.Next(10).ToString());
return s;
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

InitializeComponent();
base.OnInit(e);
}

//<summary>
// Required method for Designer support - do not modify
// the contents of this method with the code editor.
// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("initial catalog=rajitha;data source=sys01;user id=sa");

con.Open();
// SqlDataReader dr = null;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select Emailid,password from tbl_registration where Emailid='" + TextBox1.Text + "' and password='" + TextBox2.Text + "'";
cmd.CommandType = CommandType.Text;
SqlDataReader dr = cmd.ExecuteReader();
// string uname = TextBox1.Text;
//string pwd = TextBox2.Text;
// if (dr.HasRows)
// {
if (dr.Read())
{
Session["Emailid"] = TextBox1.Text;
Session["password"] = TextBox2.Text;
// if (uname == dr["Emailid"].ToString() && pwd == dr["password"].ToString())
Server.Transfer("Default2.aspx");
return;
}
else
{
Response.Write("you have entered incorrect user name,password");
// label3.Text = "you have entered incorrect username,password";
a = a + 1;
if (a > 2)
{
lb1.Enabled = true;
lb2.Enabled = true;
lb3.Enabled = true;
CodeNumberTextBox.Enabled= true;
rfd.Enabled=true;
MessageLabel.Enabled=true;
SubmitButton.Enabled = true;
img1.Visible =true;
}
}
}
con.Close();
}
}

}
Aug 26 '08 #1
0 1564

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

Similar topics

4
by: Krishna Kumar | last post by:
Hai all, I am doing a project in .net and in that project I have a problem in capturing text from an image. i.e images like CAPTCHA images . which has inbuilt text with in the image.So,...
3
by: ldHH | last post by:
Hi all, Some web sites (for example mySpace) had in the registration form an image with alfanumeric chars... used to check the submit Could you say me ... how can I realize this ?? Or could you...
0
by: want2learn | last post by:
Hi. I have this CAPTCHA image for .Net in C-Sharp and translate it into VB and as Code_Behind. http://www.mbarrick.com/blog/d6plinks/20061221-01 If i run the site/script i get the site but...
0
by: aaronwmail-usenet | last post by:
Announcing SkimpyGimpy Support for PNG image CAPTCHA generation and PNG canvases. You can now use SkimpyGimpy to generate CAPTCHA text representations as PNG image files in addition to...
7
by: mitchell | last post by:
hi i m using IE 6.0. i want to refresh just the captcha part when the user clicks on an image. i searched for articles on it and got a fairly good understanding of it. but i m still unable to...
4
by: xeiter | last post by:
Hi, I have a captcha script on my website located at /captcha.php. What it does it generates an image with the code, displays the image (gd2) and saves the value of the code in session. How do I...
4
by: mathewgk80 | last post by:
Hi all, I displaed some random numbers in a textbox.. I am having a captcha image and i would like to display that random numbers in captcha image.. The code i used to display the random...
11
by: Twayne | last post by:
Hi, Learning PHP code; playing with various methods of generating captcha codes: In the code below, how would I change the size of the text displayed in the captcha code? Is it even possible...
10
by: jeddiki | last post by:
Hi, I have a captcha script which should pick up a background image and add some random letters to it and re-display This is the part of the form that the captcha image is part of: <span...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.