C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




doubt


Posted Date: 28 Aug 2008      Total Responses: 4

Posted By: rajitha       Member Level: Silver     Points: 1


hai,
i have a doubt in this coding,
the page should be navigated to default2.aspx page when i enter correct uname,pwd,image text.but i didnt get like that bcoz i have little bit confusion wher place if condition which checks the img text.can you tell me?
when i clicked button which navigate to next page for both
(i.e for only checking uname,pwd and also for img text)
---------------------------------------------
this condition is for img text comparison
------------------------------------------------------------------------

// if (CodeNumberTextBox.Text == Session["CaptchaImageText"].ToString())
------------------------------------------------------------------------

protected void Button1_Click(object sender, EventArgs e)
{
// On a postback, check the user input.

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 username,password from tb_login where username='" + TextBox1.Text + "' and password='" + TextBox2.Text + "'";//where Emailid='" + TextBox1.Text + "' and password='" + TextBox2.Text + "'";
cmd.CommandType = CommandType.Text;
SqlDataReader dr = cmd.ExecuteReader();
string un = TextBox1.Text;
string pd = TextBox2.Text;
// if (dr.HasRows)
// {
//
if (dr.Read())
{
string uname = dr["username"].ToString();
string pwd = dr["password"].ToString();
//Session["Emailid"] = TextBox1.Text;
//Session["password"] = TextBox2.Text;
if (un == uname && pd == pwd)

Server.Transfer("Default2.aspx");
return;

}
-----------------------------------------------------------
below code for displaying captcha
-----------------------------------------------------------
else
{
Response.Write("you have entered incorrect user name,password");
// label3.Text = "you have entered incorrect username,password";
a = a + 1;

if (a > 2)
{
CodeNumberTextBox.Text = "";
Session["CaptchaImageText"] = GenerateRandomCode();
------------------------------------------------------------
enabling captcha controls which i disable in page load
----------------------------------------------------------
lb1.Visible = true;
lb2.Visible = true;
lb3.Visible = true;
CodeNumberTextBox.Visible = true;
rfd.Visible = true;
img1.Visible = true;

}


}
con.Close();


}




Responses

Author: S.Boovaragan    28 Aug 2008Member Level: SilverRating:     Points: 3
string uname = dr["username"].ToString();
string pwd = dr["password"].ToString();

Both statements will have same value
then what is the need of comparison


Author: vipul    28 Aug 2008Member Level: DiamondRating:     Points: 4
hi,
Please specify that you want to check user name , password and image text at the button click event or you want user enter username and password but it is incorrcte then you display image text and user enter image text then you redirect to other page you want this way.

vipul,
http://dongavipul.blgospot.com


Author: ANIL PANDEY    28 Aug 2008Member Level: DiamondRating:     Points: 6
Hello,

Refer this code....


protected void btnLogin_Click(object sender, ImageClickEventArgs e)
{
string strLoginID = string.Empty;
string strPassword = string.Empty;
string strQuery;
string strUname;
string strPwd;
SqlDataReader drd;
SqlConnection con = new SqlConnection(strConStr);
SqlCommand cmd = new SqlCommand();

strLoginID = txtLoginID.Text;
strPassword = txtPassword.Text;
strQuery = "Select Sno,UserName,Pwd from tbUsers where UserName='" + txtLoginID.Text.Trim() + "' and Ac_Status='E'";
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
drd = cmd.ExecuteReader();

if (drd.HasRows)
{
while( drd.Read())
{
if ((drd["UserName"].ToString() == txtLoginID.Text.Trim()) && (drd["Pwd"].ToString() == txtPassword.Text.Trim()))
{
Session["UID"] = drd[0].ToString();
Session["UName"] = drd[1].ToString();
Response.Redirect("attsheet.aspx");
}
else
{
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "Invalid login ID or password.";
txtLoginID.Text = "";
txtPassword.Text = "";
txtLoginID.Focus();
}
}
}
else
{
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "User does not exist.";
txtLoginID.Text = "";
txtPassword.Text = "";
txtLoginID.Focus();
}
}


Hope u got idea..

Thanks
Anil



Author: Athira Appukuttan    28 Aug 2008Member Level: DiamondRating:     Points: 6
HHi...


SQLHelper OldEmp = new SQLHelper();
SqlDataReader OldEmployee = OldEmp.ExecuteReader("select * from tablename");
while (OldEmployee.Read())
{
string name = OldEmployee["firstname"].ToString();
string pwd = OldEmployee["pwd"].ToString();
if((string.compare(name,textbox1.text) && (string.compare(pwd,textbox2.text))
{
session["Uname"]=name;
session["Pwd"]=pwd;
response.redirect("Nextpage.aspx")
}
else
{
label.text="Invalid Username and Password";
label.forcolour=system.drawing.red;
response.redirect("Login.aspx");
}
}



Post Reply
You must Sign In to post a response.
Next : its very urgent
Previous : How to give scroll bar to grid view??
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

it outsourcing

Contact Us    Privacy Policy    Terms Of Use