.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

to check userid and password from database.

Posted By: kalyan     Posted Date: March 23, 2010    Points:2   Category :ASP.Net
its a login details ..i want code how to check the userid and pasword from database.. if it is valid then i want to redirect to another page.. i stored some userid and password in myu database

Responses
Author: Venkat          Accepted Answer   
Posted Date: March 23, 2010     Points: 10   

Hi Kalyan,

Take a loog at this article this will help you to check username and password from database

http://www.dotnetspark.com/kb/551-developing-login-box-simplest-way.aspx

Mark As Answer if this solve your problem
Warm Regards,
Venkat
Author: Amit Mehra             
Posted Date: March 23, 2010     Points: 5   

Hi,

Are you using Stored Procedure? or Inline SQL Query to check username?

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: kalyan             
Posted Date: March 23, 2010     Points: 5   

i am using inline sql query

Author: kalyan             
Posted Date: March 23, 2010     Points: 5   

i need the code in c#

Author: Syed Shakeer Hussain             
Posted Date: March 23, 2010     Points: 5   

Hi Kalyan,
use the following code:-


SqlCommand cmd=new SqlCommand("select username,password from login_tbl where username='"+txtusername.Text+"' and password='"+txtpassword.Text+"'",conn);
SqlDataReader dr=cmd.ExecuteReader();
if(dr.Read())
{
Server.Transfer("welcompage.aspx");
}
else
{
label1.Text="Invalid UserName Or Password");
}


Author: The King             
Posted Date: June 09, 2012     Points: 20   

ASP PAGE CODE


<table class="style1">
<tr>
<td class="style2">
<asp:Label ID="Label1" runat="server" Text="USERNAME"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="txtUserName" runat="server" BorderStyle="Solid"
BorderWidth="1px" Height="18px" Width="127px"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label2" runat="server" Text="PASSWORD"></asp:Label>
</td>
<td class="style3">
<asp:TextBox ID="txtPassword" runat="server" BorderStyle="Solid"
BorderWidth="1px" Height="18px" TextMode="Password" Width="127px"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Button ID="btnLogin" runat="server" Text="Login" BackColor="White"
BorderStyle="Solid" BorderWidth="1px" onclick="btnLogin_Click" />
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Label ID="lbStatus" runat="server"></asp:Label></td>
</tr>
</table>


BACK END CODE C#



    protected void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True";
SqlCommand cmd = new SqlCommand();
con.Open();
cmd.CommandText = @"SELECT USERNAME FROM USERS_TABLE WHERE USERNAME='"+txtUserName.Text+"' AND PASSWORD='"+txtPassword.Text+"'";
cmd.Connection = con;
object o = cmd.ExecuteScalar();
if (o == null)
{
lbStatus.Text = "Invalid login";
return;
}
Session["username"] = o;
lbStatus.Text = "Success";
con.Close();
}




Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend