Best way to check for first Login

J

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)).UserName;

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;

}

}
 
J

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top