LoginPage using Oracle Database

Posted by Satyapriyanayak under ASP.NET category on | Points: 40 | Views : 2077
We will know how to do a login page using oracle database. 
Add reference of Oracle database client library. Right click on “Add Reference” inside your project. From Add Reference dialog box click on “.Net” tab, select “System.Data.OracleClient” from Component Name. Click “OK” button to add reference.
In web.config file
<connectionStrings><add name="ConnectionString" connectionString="Data Source=XE;UserID=system;Password=pintu;Persist Security Info=True;Connection Lifetime=10" providerName="System.Data.OracleClient"></add></connectionStrings>

Default.aspx code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="LoginPage_using_Oracle_Db._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript" language="javascript">
function Validate()
var UName=document.getElementById('TextBox_user_name');
var Password=document.getElementById('TextBox_password');
if((UName.value=='') || (Password.value==''))
alert('UserName or Password should not be blank');
return false;
return true;
<form id="form1" runat="server">
<asp:Label ID="lb1" runat="server" Font-Bold="True" ForeColor="#FF3300"></asp:Label><br />
<asp:Label ID="Label1" runat="server" Text="UserName" Font-Bold="True" Width="100px" BackColor="#FFFF66" ForeColor="#FF3300"></asp:Label>
<asp:TextBox ID="TextBox_user_name" runat="server" ForeColor="#993300" Width="100px"></asp:TextBox><br />
<asp:Label ID="Label2" runat="server" Text="Password" Font-Bold="True" Width="100px" BackColor="#FFFF66" ForeColor="#FF3300"></asp:Label>
<asp:TextBox ID="TextBox_password" runat="server" ForeColor="#CC6600" TextMode="Password" Width="100px"></asp:TextBox><br />
<asp:Button ID="btn_login" runat="server" Text="Login" Font-Bold="True" BackColor="#CCFF99" OnClientClick="Validate()" onclick="btn_login_Click"
/><br /> </div></form></body></html>

Default.aspx.cs code
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OracleClient;
namespace LoginPage_using_Oracle_Db
public partial class _Default : System.Web.UI.Page
string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
OracleCommand com;
OracleDataAdapter orada;
string str;
DataTable dt;
int RowCount;
protected void btn_login_Click(object sender, EventArgs e)
string UserName = TextBox_user_name.Text.Trim();
string Password = TextBox_password.Text.Trim();
OracleConnection con = new OracleConnection(strConnString);
str = "Select * from Login";
com = new OracleCommand(str);
orada = new OracleDataAdapter(com.CommandText, con);
dt = new DataTable();
RowCount = dt.Rows.Count;
for (int i = 0; i < RowCount; i++)
UserName = dt.Rows[i]["UserName"].ToString();
Password = dt.Rows[i]["Password"].ToString();
if (UserName == TextBox_user_name.Text && Password == TextBox_password.Text)
Session["UserName"] = UserName;
lb1.Text = "Invalid User Name or Password! Please try again!";

Comments or Responses

Login to post response