N
NITIN MUNJAL
I am trying to implement a simple way to authenticate users before
entering my webpage. I have two textboxes one each for username and
password. On the button click I call the function authenticate() which
is written below. It queries to an access database db.mdb which has 3
fields id, usernames and passwords. However this doesnt seem to work as
I seem to get an exception always on the line maked by *** and the
print statement in the catch statement is executed each time. Could
someone help me out on this please as to where am I going wrong?
//Code Snippet
public void authenticate()
{
int i=0;
string StrConn=@"Provider=Microsoft.Jet.OLEDB.4.0 ;Data
Source=" + Server.MapPath("/db.mdb");
OleDbConnection myConn=new OleDbConnection(StrConn);
string strCon="SELECT * FROM authenticate WHERE
uname="+UserName.Text;
OleDbCommand oledbcomm = new OleDbCommand(strCon, myConn) ;
myConn.Open();
try{
**** OleDbDataReader reader = oledbcomm.ExecuteReader();
reader.Read();
string pass=reader.GetString(2);
if(pass==UserPass.Text)
{
i=reader.GetInt32(0);
reader.Close();
myConn.Close();
if(i==0)
Msg.Text = "Invalid Credentials: Please try again";
else
Response.Redirect("default.aspx");
}
else
{
reader.Close();
myConn.Close();
Msg.Text="Username and password do not match. (You
provided "+UserName.Text+")";
}
}
catch (System.Data.OleDb.OleDbException e){Msg.Text="Usernaword do
not match. (You provided "+UserName.Text+")";}
}
TIA
Nitin
entering my webpage. I have two textboxes one each for username and
password. On the button click I call the function authenticate() which
is written below. It queries to an access database db.mdb which has 3
fields id, usernames and passwords. However this doesnt seem to work as
I seem to get an exception always on the line maked by *** and the
print statement in the catch statement is executed each time. Could
someone help me out on this please as to where am I going wrong?
//Code Snippet
public void authenticate()
{
int i=0;
string StrConn=@"Provider=Microsoft.Jet.OLEDB.4.0 ;Data
Source=" + Server.MapPath("/db.mdb");
OleDbConnection myConn=new OleDbConnection(StrConn);
string strCon="SELECT * FROM authenticate WHERE
uname="+UserName.Text;
OleDbCommand oledbcomm = new OleDbCommand(strCon, myConn) ;
myConn.Open();
try{
**** OleDbDataReader reader = oledbcomm.ExecuteReader();
reader.Read();
string pass=reader.GetString(2);
if(pass==UserPass.Text)
{
i=reader.GetInt32(0);
reader.Close();
myConn.Close();
if(i==0)
Msg.Text = "Invalid Credentials: Please try again";
else
Response.Redirect("default.aspx");
}
else
{
reader.Close();
myConn.Close();
Msg.Text="Username and password do not match. (You
provided "+UserName.Text+")";
}
}
catch (System.Data.OleDb.OleDbException e){Msg.Text="Usernaword do
not match. (You provided "+UserName.Text+")";}
}
TIA
Nitin