![]() |
| ||
| login validation hi i am asp.net beginner, i doing login validation using asp.net in c#.here i was create the db in sql server 2005 ,fetch the data from db and compare the text box value. if condition error will be show..it is using visual studio 2005 .. given below my code plz correct the error. using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.Sql; using System.Data.SqlClient; public partial class index : System.Web.UI.Page { SqlConnection conjds = new SqlConnection(); SqlCommand cmdjds = new SqlCommand(); SqlDataReader redjds; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string log1, pass1, cid; string login1, pass2, client1; //log1 = username.Text; //pass1 = pass.Text; //cid = clientid.Text; conjds.ConnectionString = ConfigurationManager.ConnectionStrings["maillog"].ToString(); conjds.Open(); cmdjds.Connection = conjds; cmdjds.CommandText = "Select * from login "; cmdjds.ExecuteNonQuery(); redjds = cmdjds.ExecuteReader(); while (redjds.Read()) { login1 = redjds.GetString(0); pass2 = redjds.GetString(1); client1 = redjds.GetString(2); } if (username.Text = "login1" && pass.Text = "pass2" && clientid.Text = "client1" ) { Response.Redirect("~/assign.aspx"); } else { Response.Write("wrong"); } conjds.Close(); } |
| ||
| Re: login validation Hi psathish2, Quote:
Quote:
if(username.Text == login1 && pass.Text == pass2 && clientid.Text == client1) Instead OF if(username.Text = "login1" && pass.Text = "pass2" && clientid.Text = "client1") OR you can use String1.Equals(String2) function to campare two strings. So if condtion should be if(username.Text.Equals(login1) && pass.Text.Equals(pass2) && clientid.Text.Equals(client1)) Hope this will help you. If problem persist feel free to ask again to me. Thanks & Regards Dilip Kumar Vishwakarma Programmer .Net Consulting |
| ||
| Re: login validation Hey, there are many things that are wrong and need updating, so I will lead you through it: conjds.ConnectionString = ConfigurationManager.ConnectionStrings["maillog"].ToString();Hope I helped and gave you insight. |
| ||
| Re: login validation thank you for information again this error should accorded.. using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.Sql; using System.Data.SqlClient; public partial class index : System.Web.UI.Page { SqlConnection conjds = new SqlConnection(); SqlCommand cmdjds = new SqlCommand(); SqlDataReader redjds; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { string login1, pass2, client1; conjds.ConnectionString = ConfigurationManager.ConnectionStrings["maillog"].ToString(); conjds.Open(); cmdjds.Connection = conjds; cmdjds.CommandText = "SELECT username,password,clientid FROM login WHERE username=@username"; //trim is not suport here.. cmdjds.Parameters.AddWithValue("@username",Trim(username.Text)); // cmdjds.ExecuteNonQuery(); //redjds = cmdjds.ExecuteReader(); while (redjds.Read()) { login1 = redjds.GetString(0); pass2 = redjds.GetString(1); client1 = redjds.GetString(2); } conjds.Close(); //here use of unassign local variable 'login1','pass2','client1' error is coming if (username.Text == login1 && pass.Text == pass2 && clientid.Text == client1) { Response.Redirect("~/assign.aspx"); } else { Response.Write("wrong"); } } } |
| ||
| Re: login validation hi |
| ||
| Re: login validation Sorry, I am a VB.NET developer, so I mis did some syntax (Like trim). Try the new code: conjds.ConnectionString = ConfigurationManager.ConnectionStrings["maillog"].ToString(); |
| ||
| Re: login validation If that fails at the if statement, replace it with: if(username.Text.Equals(login1) && pass.Text.Equals(pass2) && clientid.Text.Equals(client1)) |
| ||
| Re: login validation thank you for your coding but not working if condition not working else part to execute... string login1, pass2, client1; conjds.ConnectionString = ConfigurationManager.ConnectionStrings["maillog"].ToString(); conjds.Open(); cmdjds.Connection = conjds; cmdjds.CommandText = "SELECT username,password,clientid FROM login WHERE username=@username"; cmdjds.Parameters.AddWithValue("@username",username.Text.Trim()); redjds = cmdjds.ExecuteReader(); while (redjds.Read()) { login1 = redjds.GetString(0); pass2 = redjds.GetString(1); client1 = redjds.GetString(2); // before i put in close bracket in while loop error showed login1,pass2,client1 unassign variable ... so i changed put in bracket in last ... //if (username.Text.Equals(login1) && pass.Text.Equals(pass2) && clientid.Text.Equals(client1)) if (login1 == username.Text.Trim() && pass2 == pass.Text.Trim() && client1 == clientid.Text.Trim()) { Response.Redirect("~/assign.aspx"); } else { Response.Write("wrong"); } } conjds.Close(); } o/p: wrong only printed...... |
| ||
| Re: login validation thank you for everbody help to me..i got results... |
| All times are GMT -4. The time now is 1:28 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC