473,406 Members | 2,710 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,406 software developers and data experts.

Best way to check for first Login

JJ
I am comparing the 'lastloggedin' and 'createddate' fields of the membership
table to see if this is the first time the user has logged in.
(if they are within 1 second on each other I presume this is the first
login).

I have worked out that I can't check for this in the 'onLoggedIn' event, as
this is after the 'lastloggedin' field is updated. So, I am trying to do the
check in the 'onAuthenticate' event.

However, when I add this handler I stop the authentication taking place.
How do I let authentication take place normally whilst still running my
extra code?
Or, is there another way to check for first login?
JJ

i.e.:
protected void OnAuthenticate(object sender, AuthenticateEventArgs e)

{
string thisUsername = ((System.Web.UI.WebControls.Login)(sender)).UserNa me;

DateTime CreatedDateTime = Membership.GetUser(thisUsername).CreationDate;

DateTime LastLoggedInDateTime =
Membership.GetUser(thisUsername).LastLoginDate;

System.TimeSpan TimeDiff = LastLoggedInDateTime.Subtract(CreatedDateTime);

//Probably only need 2 seconds max

if (TimeDiff.TotalSeconds < 2)

{

//this is first login

FirstLogin = true;

}

}
Sep 22 '06 #1
1 2632
JJ
As I had no reaponses I guess I was either on the wrong tracks totally, or
no one had a work around.

In the end, I added extra properties to the users profile and checked those
upon logging in (i.e. I didn't use the onAuthenticate event at all)

JJ

"JJ" <ab*@xyz.comwrote in message
news:Oz**************@TK2MSFTNGP03.phx.gbl...
>I am comparing the 'lastloggedin' and 'createddate' fields of the
membership table to see if this is the first time the user has logged in.
(if they are within 1 second on each other I presume this is the first
login).

I have worked out that I can't check for this in the 'onLoggedIn' event,
as this is after the 'lastloggedin' field is updated. So, I am trying to
do the check in the 'onAuthenticate' event.

However, when I add this handler I stop the authentication taking place.
How do I let authentication take place normally whilst still running my
extra code?
Or, is there another way to check for first login?
JJ

i.e.:
protected void OnAuthenticate(object sender, AuthenticateEventArgs e)

{
string thisUsername =
((System.Web.UI.WebControls.Login)(sender)).UserNa me;

DateTime CreatedDateTime = Membership.GetUser(thisUsername).CreationDate;

DateTime LastLoggedInDateTime =
Membership.GetUser(thisUsername).LastLoginDate;

System.TimeSpan TimeDiff = LastLoggedInDateTime.Subtract(CreatedDateTime);

//Probably only need 2 seconds max

if (TimeDiff.TotalSeconds < 2)

{

//this is first login

FirstLogin = true;

}

}


Sep 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: FLEB | last post by:
I'm working on a logon system, something generic and modular, as a part of a few ideas I have running. I'm just wondering, though, what is the best way to keep a user logged in authentically...
15
by: Joshua Beall | last post by:
Hi All, What is the best way to use a cookie to remember a logged in user? Would you store the username and password in two separate cookies? Should the password be plain text? Hashed? Not...
6
by: Rich | last post by:
Hello, I need users to access a data entry asp page via a login page. If they bookmark the data entry asp I want to redirect them to the login page (using IIS). Here is what I had in mind: ...
0
by: n33470 | last post by:
In a desktop application, is there a best practice to implement a check at login time to ensure that the number of active users has not exceeded a limit? In our application, we intend to sell...
4
by: Andrew Banks | last post by:
I'm going to have an admin section to a site I'm developing using ASP.NET C# I want to restrict access to this directory based on username and password (I've got that bit done) but also upon the...
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
5
by: Jon | last post by:
I am setting a session var upon login that holds some data about the user. I need to check on every page to make sure the data is populated so if a user bypasses the login page they are redirected...
20
by: Keith G. Murphy | last post by:
I'm trying to get a feel for what most people are doing or consider best practice. Given a mod_perl application talking to a PostgreSQL database on the same host, where different users are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.