Forums

ASP

This topic is locked

Count User-login To Database

Posted 16 Oct 2008 21:47:27
1
has voted
16 Oct 2008 21:47:27 Christian Sen posted:
Hi there!

I'm trying to count member logins to a database (Access), no luck of course so I'm hoping someone here can point me in the right direction.

What I would like to do is make a date/time stamp in the db when members log in and at the same time increase the number of logins by +1. Have an Access database with users.

I'm a novice when it comes to programing, but if someone could show me what door to open I'm more than willing to spend hours learning, no need to give me the whole book if you're in a hurry.

Been searching the web/forums/google for information about this topic, but no luck so far.

Thanx in advance, regards
Christian Sen

(Dreamweaver, Access, Asp)



Edited by - Sarre on 20 Oct 2008 20:19:59

Replies

Replied 25 Mar 2009 06:12:48
25 Mar 2009 06:12:48 dave blohm replied:
first question...how many users you intend to serve content to on this Access DB?
Replied 25 Mar 2009 21:57:15
25 Mar 2009 21:57:15 Christian Sen replied:
Hi Dave!

I'm thinking not more than 20 users.
Replied 26 Mar 2009 21:24:15
26 Mar 2009 21:24:15 dave blohm replied:
ok...given my understanding of what you're trying to do, here's the solution I came up with...quick, down and dirty, without any sort of validation or anything...but functional:


<%' set the connection string
str_conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath("\") & "\dmxzone\login_count\demo.mdb;User ID=Admin;Password="
' see if the user is trying to log out
if request.QueryString("func") = "logout" then
	session.abandon()
	response.redirect request.servervariables("SCRIPT_NAME")
end if

' see if the user is trying to log in
if request.form("func") = "login" then
	Set rs_login_cmd = server.createobject ("ADODB.Command")
	rs_login_cmd.activeConnection = str_conn 
	rs_login_cmd.commandtext = "select * from users where username='" & request.form("username") & "' and password='" & request.Form("password")  & "'" 
	rs_login_cmd.prepared = true
	Set rs_login = rs_login_cmd.execute
	
	' login is successful
	if not rs_login.eof then
		session("user_id") = rs_login("id")
		' update the login_date and login_count fields
		Set rs_update_cmd = server.createobject ("ADODB.Command")
		rs_update_cmd.activeConnection = str_conn 
		rs_update_cmd.commandtext = "update users set login_count =(login_count + 1), last_login=date() where id = " & cint(session("user_id")) 
		rs_update_cmd.prepared = true
		rs_update_cmd.execute
	end if
end if


%>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DMXZone Demo :: count user login</title>
</head>

<body onload="document.getElementById('username').focus()">
<% 
' if our visitor is logged show some user specific info
if session("user_id") then 
%>
	logged in as <%= rs_login("username")%>. <a href="index.asp?func=logout">log out</a>
<
%' if not, show the login form
else
%>
<form id="frm_login" method="post">
	<input type="text" name="username" id="username" />
	<input type="password" name="password" id="password" />
	<input type="submit" name="button" id="button" value="Submit" />
	<input type="hidden" name="func" id="func" value="login" />
</form>	
<%end if%>
</body>
</html>



hope this helps

Edited by - dave blohm on 26 Mar 2009  21:25:05
Replied 27 Mar 2009 00:39:18
27 Mar 2009 00:39:18 Christian Sen replied:
Wow!

Can't wait to implement the code you've provided and do a little testout this weekend.
Thank you very much for your time and effort! -greatly appreciated!

Best regards,
Christian
Replied 23 Apr 2009 00:42:17
23 Apr 2009 00:42:17 Christian Sen replied:
-just a little follow up question:

I already have the login behaviour set by DW.
How do I implement the lines 17-27 from the code you provided?
(the part where the login_count and last_login is updating the DB..)

I've tried my way around it, but I'm not that steady when it comes to hardcoding.
Too many IF's and BOF's

Replied 15 Apr 2010 18:32:31
15 Apr 2010 18:32:31 Christian Sen replied:
Been a while, still haven't figured out this one. Anybody else know how to implement Dave's code to the DW standard Log in Behaviour?

I have tried numerous ways but no luck so far..
Replied 27 Apr 2010 18:13:17
27 Apr 2010 18:13:17 Seb Adlington replied:
Hi Christian,

Looks like you've been a long time waiting!
If you could post the code from your login page, we'll have a quick look see for you

Cheers

Seb
Replied 27 Apr 2010 20:05:37
27 Apr 2010 20:05:37 Christian Sen replied:
Hi Seb, finally someone picked up my cry for help []

I have tried to implement Dave's code numerous places and numerous ways, but no luck so far. Hoping that someone with a better understanding might see the solution.

HEAD SECTION OF INDEX/LOGINPAGE:


<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="Connections/KamelConn.asp" -->

<
%' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString<>"" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
MM_valUsername=CStr(Request.Form("Username"))
If MM_valUsername <> "" Then
  MM_fldUserAuthorization="accesslevel"
  MM_redirectLoginSuccess="main.asp"
  MM_redirectLoginFailed="index.asp"
  MM_flag="ADODB.Recordset"
  set MM_rsUser = Server.CreateObject(MM_flag)
  MM_rsUser.ActiveConnection = MM_KamelConn_STRING
  MM_rsUser.Source = "SELECT username, password"
  If MM_fldUserAuthorization <> "" Then MM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization
  MM_rsUser.Source = MM_rsUser.Source & " FROM Users WHERE username='" & Replace(MM_valUsername,"'","''") &"' AND password='" & Replace(Request.Form("password"),"'","''") & "'"
  MM_rsUser.CursorType = 0
  MM_rsUser.CursorLocation = 2
  MM_rsUser.LockType = 3
  MM_rsUser.Open
  If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then 
    ' username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername
    If (MM_fldUserAuthorization <> "") Then
      Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
    Else
      Session("MM_UserAuthorization") = ""
    End If
    if CStr(Request.QueryString("accessdenied")) <> "" And false Then
      MM_redirectLoginSuccess = Request.QueryString("accessdenied")
    End If
    MM_rsUser.Close
    Response.Redirect(MM_redirectLoginSuccess)
  End If
  MM_rsUser.Close
  Response.Redirect(MM_redirectLoginFailed)
End If

%> 


Edited by - Christian Sen on 27 Apr 2010  20:25:40
Replied 28 Apr 2010 11:52:21
28 Apr 2010 11:52:21 Seb Adlington replied:
Hi Christian,


Try this, not had long to look at it yet let me know how it goes and I will have a better look this afternoon

Cheers

Seb

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>  
<!--#include file="Connections/KamelConn.asp" -->  
  
<  
%' *** Validate request to log in to this site.  
MM_LoginAction = Request.ServerVariables("URL")  
If Request.QueryString<>"" Then MM_LoginActionMM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)  
MM_valUsername=CStr(Request.Form("Username"))  
If MM_valUsername <> "" Then  
  MM_fldUserAuthorization="accesslevel"  
  MM_redirectLoginSuccess="main.asp"  
  MM_redirectLoginFailed="index.asp"  
  MM_flag="ADODB.Recordset"  
  set MM_rsUser = Server.CreateObject(MM_flag)  
  MM_rsUser.ActiveConnection = MM_KamelConn_STRING  
  MM_rsUser.Source = "SELECT username, password"  
  If MM_fldUserAuthorization <> "" Then MM_rsUserMM_rsUser.Source = MM_rsUser.Source & "," & MM_fldUserAuthorization  
  MM_rsUserMM_rsUser.Source = MM_rsUser.Source & " FROM Users WHERE username='" & Replace(MM_valUsername,"'","''") &"' AND password='" & Replace(Request.Form("password"),"'","''") & "'"  
  MM_rsUser.CursorType = 0  
  MM_rsUser.CursorLocation = 2  
  MM_rsUser.LockType = 3  
  MM_rsUser.Open  
  If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then   
    ' username and password match - this is a valid user  
    Session("MM_Username") = MM_valUsername  
    If (MM_fldUserAuthorization <> "") Then  
      Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)  
    Else  
      Session("MM_UserAuthorization") = ""  
    End If  
    if CStr(Request.QueryString("accessdenied")) <> "" And false Then  
      MM_redirectLoginSuccess = Request.QueryString("accessdenied")  
    End If  
    MM_rsUser.Close 
	
	' //  Sebs Code
	
  MM_flag="ADODB.Recordset"  
  set MM_rsUser = Server.CreateObject(MM_flag)  
  MM_rsUser.ActiveConnection = MM_KamelConn_STRING  
  MM_rsUser.Source = "UPDATE Users SET login_count = (login_count + 1), last_login = date() WHERE username = '" & Session("MM_Username") & "'"  
  MM_rsUser.Open  
  MM_rsUser.Close 
  
	' // End Seb Code
	
    Response.Redirect(MM_redirectLoginSuccess)  
  End If  
  MM_rsUser.Close  
  Response.Redirect(MM_redirectLoginFailed)  
End If  
  
%>   



Replied 28 Apr 2010 23:58:30
28 Apr 2010 23:58:30 Christian Sen replied:
Hi Seb,
-thank you so much for taking your time to look at this!!

I tested out your suggestion, and it worked halfway, the date was set but the login_count left a blank spot in the database. Probably just a minor adjustment.

Any clues?


C
Replied 29 Apr 2010 11:15:16
29 Apr 2010 11:15:16 Seb Adlington replied:
at a rough guess, you probably don't have any values in the login_count field - so it's trying to add 1 to null which won't work - you can either populate the login fields to 1 and set that as a default value and use the code as is, otherwise try this version which is a better solution


    
' //  Sebs Code 
  dim loginCount
 
      
  MM_flag="ADODB.Recordset"    
  set seb_rsUser = Server.CreateObject(MM_flag)    
  seb_rsUser.ActiveConnection = MM_KamelConn_STRING
  seb_rsUser.Source = "select login_count from Users WHERE username = '" & Session("MM_Username") & "'"    
  seb_rsUser.Open   

loginCount = (seb_rsUser.Fields.Item("login_count").Value)

  
  MM_flag="ADODB.Recordset"    
  set MM_rsUser = Server.CreateObject(MM_flag)    
  MM_rsUser.ActiveConnection = MM_KamelConn_STRING
  if(loginCount > 0 ) then 
  MM_rsUser.Source = "UPDATE Users SET login_count = (login_count + 1), last_login = date() WHERE username = '" & Session("MM_Username") & "'"    
  else 
    MM_rsUser.Source = "UPDATE Users SET login_count = 1, last_login = date() WHERE username = '" & Session("MM_Username") & "'"    
  end if
  MM_rsUser.Open    
  MM_rsUser.Close 
  
   seb_rsUser.Close
    
    ' // End Seb Code  





Edited by - Seb Adlington on 29 Apr 2010  11:17:39
Replied 29 Apr 2010 17:38:46
29 Apr 2010 17:38:46 Christian Sen replied:
Solved!

You wouldn't believe how much time I've spent trying to figure this one out. Thanks to you, and Dave, I can now concentrate on the rest of the site.

Thank you very much! []

Christian
Replied 16 Feb 2013 19:45:08
16 Feb 2013 19:45:08 Christian Sen replied:
Hi Seb! -Hopefully you're still here

I rebuildt the site and tried to implement your code, but something keeps crashing no matter what I try. Tried out both your suggestions, but there is appearently a syntax eror somewhere in the code. And I'm sorry to say that I yet don't have the skills to find where the error is.

I have embedded the head coding of index.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<

%  Response.Buffer = True

  Response.ExpiresAbsolute = Now() - 1

  Response.Expires = 0

  Response.CacheControl = "no-cache"

%>
<!--#include virtual="/Connections/KamCon.asp" -->
<
%' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString <> "" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
MM_valUsername = CStr(Request.Form("brukernavn"))
If MM_valUsername <> "" Then
  Dim MM_fldUserAuthorization
  Dim MM_redirectLoginSuccess
  Dim MM_redirectLoginFailed
  Dim MM_loginSQL
  Dim MM_rsUser
  Dim MM_rsUser_cmd
  
  MM_fldUserAuthorization = "Adgang"
  MM_redirectLoginSuccess = "main.asp"
  MM_redirectLoginFailed = "index.asp"

  MM_loginSQL = "SELECT Brukernavn, Passord, Fornavn"
  If MM_fldUserAuthorization <> "" Then MM_loginSQL = MM_loginSQL & "," & MM_fldUserAuthorization
  MM_loginSQL = MM_loginSQL & " FROM Users WHERE Brukernavn = ? AND Passord = ?"
  Set MM_rsUser_cmd = Server.CreateObject ("ADODB.Command")
  MM_rsUser_cmd.ActiveConnection = MM_KamCon_STRING
  MM_rsUser_cmd.CommandText = MM_loginSQL
  MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param1", 200, 1, 255, MM_valUsername) ' adVarChar
  MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param2", 200, 1, 255, Request.Form("password")) ' adVarChar
  MM_rsUser_cmd.Prepared = true
  Set MM_rsUser = MM_rsUser_cmd.Execute

  If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then 
    ' username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername
	Session("Fornavn") = MM_rsUser("Fornavn")
	Session.Contents.Remove("iCount")
    If (MM_fldUserAuthorization <> "") Then
      Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
    Else
      Session("MM_UserAuthorization") = ""
    End If
    if CStr(Request.QueryString("accessdenied")) <> "" And false Then
      MM_redirectLoginSuccess = Request.QueryString("accessdenied")
    End If
    MM_rsUser.Close
	    ' //  Sebs Code  
      
  MM_flag="ADODB.Recordset"    
  set MM_rsUser = Server.CreateObject(MM_flag)    
  MM_rsUser.ActiveConnection = MM_KamCon_STRING    
  MM_rsUser.Source = "UPDATE Users SET LoginCount = (LoginCount + 1), LastLogin = date() WHERE Brukernavn = '" & Session("MM_Username") & "'"    
  MM_rsUser.Open    
  MM_rsUser.Close   
    
    ' // End Seb Code 
    Response.Redirect(MM_redirectLoginSuccess)
  End If
  MM_rsUser.Close
  Session("iCount") = Session("iCount") + 1
  Response.Redirect(MM_redirectLoginFailed)
End If
%>


Forgot the error message...

ADODB.Recordset error '800a0e78'

Operation is not allowed when the object is closed.

/index.asp, line 63


Line63 is where Seb's code is closed
(MM_rsUser.Close)


Regards, Christian
Replied 18 Feb 2013 08:47:30
18 Feb 2013 08:47:30 Seb Adlington replied:
Hi Christian,

Still here - tho not been on this site in quite a while! In fact, hung up my ASp hat a few years ago but I think I can help!

There is some code missing. The code that sets the logincount variable - If you look at the original code I sent you - The update statement for the login_count will be failing so the connection is never opened....so can't be closed.


loginCount = (seb_rsUser.Fields.Item("login_count".Value)


if(loginCount > 0 ) then
MM_rsUser.Source = "UPDATE Users SET login_count = (login_count + 1), last_login = date() WHERE username = '" & Session("MM_Username" & "'"
else
MM_rsUser.Source = "UPDATE Users SET login_count = 1, last_login = date() WHERE username = '" & Session("MM_Username" & "'"
end if
Replied 18 Feb 2013 09:02:38
18 Feb 2013 09:02:38 Christian Sen replied:
I'm sorry to hear your asp hat is on the shelf, but I'm glad you decided to stop by

It is contributions from people like yourself that stops people like me from crushing the pc, and for that I am truly greatful, thank you!

Regards,
Christian
Replied 18 Feb 2013 11:05:56
18 Feb 2013 11:05:56 Seb Adlington replied:
NO worries mate - let me know if it works
Replied 18 Feb 2013 16:56:06
18 Feb 2013 16:56:06 Christian Sen replied:
Hi again Seb!

I tried all over again and copy/paste, this time your 2nd code.
Only thing I edited was the name of the db column and the norwegian name for username (brukernavn)

Still the same error:

ADODB.Recordset error '800a0e78'

Operation is not allowed when the object is closed.

/index.asp, line 79



<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<

%  Response.Buffer = True

  Response.ExpiresAbsolute = Now() - 1

  Response.Expires = 0

  Response.CacheControl = "no-cache"

%>
<!--#include virtual="/Connections/KamCon.asp" -->
<
%' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString <> "" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
MM_valUsername = CStr(Request.Form("brukernavn"))
If MM_valUsername <> "" Then
  Dim MM_fldUserAuthorization
  Dim MM_redirectLoginSuccess
  Dim MM_redirectLoginFailed
  Dim MM_loginSQL
  Dim MM_rsUser
  Dim MM_rsUser_cmd
  
  MM_fldUserAuthorization = "Adgang"
  MM_redirectLoginSuccess = "main.asp"
  MM_redirectLoginFailed = "index.asp"

  MM_loginSQL = "SELECT Brukernavn, Passord, Fornavn"
  If MM_fldUserAuthorization <> "" Then MM_loginSQL = MM_loginSQL & "," & MM_fldUserAuthorization
  MM_loginSQL = MM_loginSQL & " FROM Users WHERE Brukernavn = ? AND Passord = ?"
  Set MM_rsUser_cmd = Server.CreateObject ("ADODB.Command")
  MM_rsUser_cmd.ActiveConnection = MM_KamCon_STRING
  MM_rsUser_cmd.CommandText = MM_loginSQL
  MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param1", 200, 1, 255, MM_valUsername) ' adVarChar
  MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param2", 200, 1, 255, Request.Form("password")) ' adVarChar
  MM_rsUser_cmd.Prepared = true
  Set MM_rsUser = MM_rsUser_cmd.Execute

  If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then 
    ' username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername
	Session("Fornavn") = MM_rsUser("Fornavn")
	Session.Contents.Remove("iCount")
    If (MM_fldUserAuthorization <> "") Then
      Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
    Else
      Session("MM_UserAuthorization") = ""
    End If
    if CStr(Request.QueryString("accessdenied")) <> "" And false Then
      MM_redirectLoginSuccess = Request.QueryString("accessdenied")
    End If
    MM_rsUser.Close
	
	' //  Sebs Code   
 dim loginCount  
   
        
  MM_flag="ADODB.Recordset"      
  set seb_rsUser = Server.CreateObject(MM_flag)      
  seb_rsUser.ActiveConnection = MM_KamCon_STRING  
  seb_rsUser.Source = "select LoginCount from Users WHERE Brukernavn = '" & Session("MM_Username") & "'"      
  seb_rsUser.Open     
  
  loginCount = (seb_rsUser.Fields.Item("LoginCount").Value) 
  
    
  MM_flag="ADODB.Recordset"      
  set MM_rsUser = Server.CreateObject(MM_flag)      
  MM_rsUser.ActiveConnection = MM_KamCon_STRING  
  if(loginCount > 0 ) then   
  MM_rsUser.Source = "UPDATE Users SET LoginCount = (LoginCount + 1), LastLogin = date() WHERE Brukernavn = '" & Session("MM_Username") & "'"      
  else   
    MM_rsUser.Source = "UPDATE Users SET LoginCount = 1, LastLogin = date() WHERE Brukernavn = '" & Session("MM_Username") & "'"      
  end if  
  MM_rsUser.Open      
  MM_rsUser.Close   
    
   seb_rsUser.Close
      
    ' // End Seb Code 
    Response.Redirect(MM_redirectLoginSuccess)
  End If
  MM_rsUser.Close
  Session("iCount") = Session("iCount") + 1
  Response.Redirect(MM_redirectLoginFailed)
End If
%>


Any clues?
Replied 18 Feb 2013 17:08:44
18 Feb 2013 17:08:44 Seb Adlington replied:
Just spotted there are 2 close commands in there

Try deleting the last one

MM_rsUser.Open
MM_rsUser.Close

seb_rsUser.Close

' // End Seb Code
Response.Redirect(MM_redirectLoginSuccess)
End If

MM_rsUser.Close

Session("iCount" = Session("iCount" + 1
Response.Redirect(MM_redirectLoginFailed)
End If
Replied 18 Feb 2013 18:19:15
18 Feb 2013 18:19:15 Christian Sen replied:
You were right about the close commands. It didn't work at first but when removing the very same command from the last part of the Seb Code, the page came through and added +1 to the db. Just as planned

Am I leaving some resources open when removing that particular closing command or is it safe to go?

Head section now looks like this1

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<

%  Response.Buffer = True

  Response.ExpiresAbsolute = Now() - 1

  Response.Expires = 0

  Response.CacheControl = "no-cache"

%>
<!--#include virtual="/Connections/KamCon.asp" -->
<
%' *** Validate request to log in to this site.
MM_LoginAction = Request.ServerVariables("URL")
If Request.QueryString <> "" Then MM_LoginAction = MM_LoginAction + "?" + Server.HTMLEncode(Request.QueryString)
MM_valUsername = CStr(Request.Form("brukernavn"))
If MM_valUsername <> "" Then
  Dim MM_fldUserAuthorization
  Dim MM_redirectLoginSuccess
  Dim MM_redirectLoginFailed
  Dim MM_loginSQL
  Dim MM_rsUser
  Dim MM_rsUser_cmd
  
  MM_fldUserAuthorization = "Adgang"
  MM_redirectLoginSuccess = "main.asp"
  MM_redirectLoginFailed = "index.asp"

  MM_loginSQL = "SELECT Brukernavn, Passord, Fornavn"
  If MM_fldUserAuthorization <> "" Then MM_loginSQL = MM_loginSQL & "," & MM_fldUserAuthorization
  MM_loginSQL = MM_loginSQL & " FROM Users WHERE Brukernavn = ? AND Passord = ?"
  Set MM_rsUser_cmd = Server.CreateObject ("ADODB.Command")
  MM_rsUser_cmd.ActiveConnection = MM_KamCon_STRING
  MM_rsUser_cmd.CommandText = MM_loginSQL
  MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param1", 200, 1, 255, MM_valUsername) ' adVarChar
  MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param2", 200, 1, 255, Request.Form("password")) ' adVarChar
  MM_rsUser_cmd.Prepared = true
  Set MM_rsUser = MM_rsUser_cmd.Execute

  If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then 
    ' username and password match - this is a valid user
    Session("MM_Username") = MM_valUsername
	Session("Fornavn") = MM_rsUser("Fornavn")
	Session.Contents.Remove("iCount")
    If (MM_fldUserAuthorization <> "") Then
      Session("MM_UserAuthorization") = CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value)
    Else
      Session("MM_UserAuthorization") = ""
    End If
    if CStr(Request.QueryString("accessdenied")) <> "" And false Then
      MM_redirectLoginSuccess = Request.QueryString("accessdenied")
    End If
    MM_rsUser.Close
	
	' //  Sebs Code   
 dim loginCount  
   
        
  MM_flag="ADODB.Recordset"      
  set seb_rsUser = Server.CreateObject(MM_flag)      
  seb_rsUser.ActiveConnection = MM_KamCon_STRING  
  seb_rsUser.Source = "select LoginCount from Users WHERE Brukernavn = '" & Session("MM_Username") & "'"      
  seb_rsUser.Open     
  
  loginCount = (seb_rsUser.Fields.Item("LoginCount").Value) 
  
    
  MM_flag="ADODB.Recordset"      
  set MM_rsUser = Server.CreateObject(MM_flag)      
  MM_rsUser.ActiveConnection = MM_KamCon_STRING  
  if(loginCount > 0 ) then   
  MM_rsUser.Source = "UPDATE Users SET LoginCount = (LoginCount + 1), LastLogin = date() WHERE Brukernavn = '" & Session("MM_Username") & "'"      
  else   
    MM_rsUser.Source = "UPDATE Users SET LoginCount = 1, LastLogin = date() WHERE Brukernavn = '" & Session("MM_Username") & "'"      
  end if  
  MM_rsUser.Open         
    
   seb_rsUser.Close
      
    ' // End Seb Code 
    Response.Redirect(MM_redirectLoginSuccess)
  End If
  MM_rsUser.Close
  Session("iCount") = Session("iCount") + 1
  Response.Redirect(MM_redirectLoginFailed)
End If
%>
Replied 19 Feb 2013 08:32:24
19 Feb 2013 08:32:24 Seb Adlington replied:
Nah - that'll be fine, you are still closing the connections anyway.
Replied 19 Feb 2013 08:34:48
19 Feb 2013 08:34:48 Christian Sen replied:
All righty then, lets leave it at that.

Appreciate your time and effort Seb, thank you again

Reply to this topic