470,636 Members | 1,526 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,636 developers. It's quick & easy.

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 1405

Post your reply

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

Similar topics

4 posts views Thread by Krishna Kumar | last post: by
3 posts views Thread by ldHH | last post: by
reply views Thread by aaronwmail-usenet | last post: by
4 posts views Thread by mathewgk80 | last post: by
11 posts views Thread by Twayne | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.