469,332 Members | 7,043 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

this code is not validating properly pls help me to fix the error

hi al

i wrote a code (LOgin form) that checks the user id and if it exists validates the password but this is not all validating and simply displaying user does not exist

i am sending the code pls check and fix it pls its urgent
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Web.Security;

namespace Customer
{
/// <summary>
/// Summary description for WebForm2.
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;
protected System.Web.UI.WebControls.Button Button3;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.LinkButton LinkButton1;
protected System.Web.UI.WebControls.TextBox TextBox3;
SqlConnection con;
SqlCommand cmdc,cmds;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
try
{
con=new SqlConnection("Data Source=STAR3;Database=Customer;user id=sa;password=;");
con.Open();
cmds=new SqlCommand("select * from LoginDetails",con);
con.Close();
}
catch(Exception e1)
{
Response.Write("Connection cannot be established" +e1.Message);
}
}


private void Button1_Click(object sender, System.EventArgs e)
{
if(chkpwd(TextBox1.Text,TextBox2.Text,TextBox3.Tex t))
{
FormsAuthentication.RedirectFromLoginPage(TextBox2 .Text,true);
Response.Redirect("WebForm3.aspx");
}
else
{
TextBox3.Text="";
Response.Write("User name does not exist try again");
if(System.Convert.ToInt32(ViewState["Tries"])>1)
Response.Redirect("WebForm10.aspx");
else
{
ViewState["Tries"]=System.Convert.ToInt32(ViewState["Tries"])+1;
if(System.Convert.ToInt32(ViewState["Tries"])>3)
Response.Redirect("WebForm10.aspx");
}
}
}

private void Button3_Click(object sender, System.EventArgs e)
{

}
private bool chkpwd(string cid,string uid,string pwd)
{
bool bsuccess=false;
//pwd=FormsAuthentication.HashPasswordForStoringInCo nfigFile(pwd,"sha1");
try
{
con.Open();
cmdc=new SqlCommand("select * from LoginDetails" + " where UserID = '"+uid+"'",con);
SqlDataReader drc=cmdc.ExecuteReader();
while(drc.Read())
{
if(pwd == drc["Pawd"].ToString())
{
Response.Write("Login successful");
bsuccess=true;
}

}

con.Close();
}
catch
{
bsuccess=false;
//Response.Write(Environment.NewLine+"Error:" +e1.Message+e1.HelpLink);
con.Close();
}
return bsuccess;
}
private void LinkButton1_Click(object sender, System.EventArgs e)
{
Response.Redirect("WebForm1.aspx");
}
}
}


pls be fast its urgent thanks in advance
Nov 24 '06 #1
0 1832

Post your reply

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

Similar topics

1 post views Thread by scorpion | last post: by
2 posts views Thread by Will | last post: by
2 posts views Thread by Wally Sanford | last post: by
reply views Thread by jean-gert nesselbosch | last post: by
232 posts views Thread by robert maas, see http://tinyurl.com/uh3t | last post: by
28 posts views Thread by Mike Hofer | last post: by
76 posts views Thread by Michael Stemper | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.