473,287 Members | 1,564 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Please solve this Task. Urgent

My task is to create login control without using login control in tools. I shouldnt use sqldatasource or any other. I should use only data sets, data adapters and data readers etc.
U had created table login with fields username(varchar(50)), password(varchar(50)), firstname(varchar(50)), lastname(varchar(50)).
U had to display username , first name, last name in default.aspx page after login.
One more condition is that, if user fails login attempt more than 3 times, you hav to disable login button.
I had written code for login.aspx as


N" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server"&gt;

//int i = 1;
protected void LgnBtn_Click(object sender, EventArgs e)
{
//Application["sessioncount"] = 0;
SqlConnection con = null;
try
{
con= LoginData.GetConnection();

SqlCommand cmd = new SqlCommand("select UserName from Login where UserName = @UserName and Password = @Password", con);
cmd.Parameters.Add("@UserName", SqlDbType.VarChar, 50).Value = UIDText.Text;
cmd.Parameters.Add("@Password", SqlDbType.VarChar, 50).Value = PWDText.Text;

SqlCommand a = new SqlCommand("select FirstName from Login where UserName = @UserName and Password = @Password", con);
a.Parameters.Add("@UserName", SqlDbType.VarChar, 50).Value = UIDText.Text;
a.Parameters.Add("@Password", SqlDbType.VarChar, 50).Value = PWDText.Text;

SqlCommand b = new SqlCommand("select LastName from Login where UserName = @UserName and Password = @Password", con);
b.Parameters.Add("@UserName", SqlDbType.VarChar, 50).Value = UIDText.Text;
b.Parameters.Add("@Password", SqlDbType.VarChar, 50).Value = PWDText.Text;

String UserName = (String)cmd.ExecuteScalar();
String FirstName = (String)a.ExecuteScalar();
String LastName = (String)b.ExecuteScalar();
//if (!Page.IsPostBack)
//int i = 1;
if (UserName == null/*(FirstName == null)||(LastName==null)*/ )
{
LoginLbl.Text = "Invalid Login!";

if (((int)Application["sessioncount"]) >=3/*i>=4*/)
{
LgnBtn.Enabled = false;
LoginLbl.Text = "Please Contact Admin for Password Recovery";
//Session.Clear();
}
//i++;
Application["sessioncount"] = (int)Application["sessioncount"] + 1;


}


else
{
Session.Add("UserName", UserName/*UIDText.Text*/);
Session.Add("FirstName", FirstName);
Session.Add("LastName", LastName);
Response.Redirect("default.aspx");

}


}
catch (Exception ex)
{
LoginLbl.Text = ex.Message;
}
finally
{
con.Close();
}


}

protected void Page_Load(object sender, EventArgs e)
{
//if (!Page.IsPostBack)
//{
// Session.Clear();
//}

//Application["sessioncount"] = (int)Application["sessioncount"] + 1;
//if ((int)Application["sessioncount"] > 3)
//{
// LgnBtn.Enabled = false;
// LoginLbl.Text = "Please Contact Admin for Password Recovery";
//}

}

//protected void Page_Unload(object sender, EventArgs e)
//{
// Application["sessioncount"] = 0;
//}

protected void Page_Disposed(object sender, EventArgs e)
{
//int i = 0;
//Session.Abandon();
Session.Clear();
// Application.Lock();
// Application["sessioncount"] = 0;
// Application.UnLock();

}

//protected void Page_AbortTransaction(object sender, EventArgs e)
//{
// Application["sessioncount"] = 0;
//}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
"Head1" runat="server">





"form1" runat="server">

"text-align: left">

"center" colspan="2"> "font-size: 14pt">Login
"width: 119px"> User ID: "UIDText" runat="server" > "RequiredFieldValidator1" runat="server" ErrorMessage="Please Enter LoginID" ControlToValidate="UIDText">
"width: 119px"> Password: "PWDText" runat="server"> "RequiredFieldValidator2" runat="server" ErrorMessage="Please Enter Password" ControlToValidate="PWDText">



"server" Text="Login" ID="LgnBtn" OnClick="LgnBtn_Click">

"LoginLbl" runat="server" Text="">




code for default.aspx

"-//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" >
"Head1" runat="server">




"form1" runat="server">

"width: 191px; height: 336px" valign="top">
"Label4" runat="server" Text="">

"Label1" runat="server" Text="">

"Label2" runat="server" Text="">



"LoginStatus1" runat="server" OnLoggingOut="LoginStatus1_LoggingOut"> "width: 788px; height: 336px" valign="top">

"Label3" runat="server" Font-Size="X-Large">










Script for default.aspx.cs

using System;
using System.Data;
using System.Configuration;
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.SqlClient;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Label4.Text = Session["UserName"].ToString();
Label1.Text = Session["FirstName"].ToString();

Label2.Text = Session["LastName"].ToString();

Label3.Text = "Welcome " + Session["FirstName"].ToString() + " " + Session["LastName"].ToString();

}


}



protected void LoginStatus1_LoggingOut(object sender, LoginCancelEventArgs e)
{
Session.Abandon();
Response.Redirect("login.aspx");
//FormsAuthentication.SignOut();
}
}


Code for global.asax


void Application_Start(object sender, EventArgs e)
{
Application["sessioncount"] = 0;
}

void Application_End(object sender, EventArgs e)
{

Application["sessioncount"] = 0;// Code that runs on application shutdown

}

void Application_Error(object sender, EventArgs e)
{
// Code that runs when an unhandled error occurs

}

void Session_Start(object sender, EventArgs e)
{
int v;
Application.Lock();
v = Convert.ToInt32(Application["sessioncount"]);
v = v + 1;
Application["sessioncount"] = v;
Application.UnLock();
}

void Session_End(object sender, EventArgs e)
{
int v;
Application.Lock();
Application["sessioncount"] = 0;
Application.UnLock();
// Code that runs when a session ends.
// Note: The Session_End event is raised only when the sessionstate mode
// is set to InProc in the Web.config file. If session mode is set to StateServer
// or SQLServer, the event is not raised.

}






Code for data connection



using System;
using System.Data;
using System.Configuration;
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.SqlClient;

/// <summary>
/// Summary description for LoginData
/// </summary>
public class LoginData
{
public static SqlConnection GetConnection()
{
SqlConnection con = new SqlConnection("Data Source=SAIBABA;Initial Catalog=OLoginCtrl;User ID=sa; pwd=sa1");

con.Open();
return con;
}

}

. I had done this using connecting datasource three times and sessions for disabling. Everything is working good. But problem comes at login attempt failed. For first time it is working in better way, but ven i close the application and running again the application, if fail atleast one time the button is disabling the button. Plz solve this problem. Urgent.
and next thing is i had to use datasets, data adapters and data readers etc for getting the user details and pass details of user to default.aspx by not using sessions. So plz solve this problem as soon as possible

Vineeth
May 4 '08 #1
2 2347
debasisdas
8,127 Expert 4TB
Question moved to .NET forum.
May 5 '08 #2
Shashi Sadasivan
1,435 Expert 1GB
Instead of storing the attempts in the session, you should lok at storing that value in the database. On every successful Login / eveney iteration of time, you should refresh thenumber of unsuccessful attempts.

Closing the browser means that at the server end the sessions will be destroyed. So thats why your sessions start from a fresh value
May 5 '08 #3

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

Similar topics

2
by: baby pink | last post by:
kindly solve the problem in article one .. its quite urgent thanx for reading goog luck pink
3
by: Liu Ju | last post by:
Dear members: I want to use the multithread in my program which is developed in Visual C++ platform (version 6). I created a controlling function: UINT CCOMM1Dlg::WritingThreadFunc(LPVOID...
6
by: Federico | last post by:
Hi, this is what I can do: - Create new solutions using VS.Net ASP.Net - Save the solutions, build the solution, view in browser with the solution still open. But, once I close the solution, I...
3
by: ricolee99 | last post by:
Hi everyone, I have a problem that i have been trying to solve for awhile. I'm given a code where the purpose is to create a general dataset mapper. Given any dataset, i have a class,...
1
by: parasuit | last post by:
HI every body I need following programs for java .........please urgent i m biggner so help me................but urgent Problem # 1 An integer is said to be prime if it is...
4
by: musai | last post by:
I have created vb oracle application I installed oracle client in three machine. All machine was reconfigured after oracle installed I could see table and record set through sql plus sheet in...
6
by: xhe | last post by:
I am using ffmpeg to convert video, this is a sample script: $str='/home/transla1/bin/ffmpeg -i /home/transla1/public_html/ cybertube/web/uploads/video/31_AK000005.AVI -s 240x180 -b 100k -ar...
2
by: =?ISO-8859-1?B?RulybmFz?= | last post by:
Hey all, I have a URGENT problem and I hope someone could help me... scenery: I have a windows app, coded using C# (framework 1.1 - VS2003)... The exe and dlls of the app is are stored in a...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.