Additional login checking

January 8, 2004 by Carl Grint

This is not actually to hard to hand write, you can simply copy the code already used in the standard Login behaviour to check your own parameters.
I do this to check a Users Account is Active, to decide whether they are logged in or not, even if giving a correct username and password.

IN the Login behaviour, locate this code

MM_valUsername=CStr(Request.Form("Username"))

Add your own definition

i.e

MM_valUsername=CStr(Request.Form("Username"))
AccountAuthorise="Confirmed" <---this requires an Account to be Confirmed

Then locate this code

  MM_rsUser.ActiveConnection = MM_prescriptions_STRING
  MM_rsUser.Source = "SELECT UserName, UserPassword"

This is where the behaviour selects the columns from the table to be used, you can simply add you own columns to this, i.e

  MM_rsUser.Source = "SELECT UserName, UserPassword, AccountStatus"

Then look for this code further down

  MM_rsUser.Source = MM_rsUser.Source & " FROM dbo.prescriptions_userdetails WHERE UserName='" & Replace(MM_valUsername,"'","''") &"' AND  UserPassword='" & Replace(Request.Form("Password"),"'","''") & "'"

Add to it so it now says thus

  MM_rsUser.Source = MM_rsUser.Source & " FROM dbo.prescriptions_userdetails WHERE UserName='" & Replace(MM_valUsername,"'","''") &"' AND AccountStatus='" & AccountAuthorise &"' AND  UserPassword='" & Replace(Request.Form("Password"),"'","''") & "'"

This final code is checking to see if the Column AccountStatus is set to the defination we defined at the top for AccountAuthorise of Confirmed.

If both the Username and Password are correct, and the AccountStatus is set to Confirmed, then the user will be logged in. If not they will be declined access.

I Admin this via the Administration system, to change a Users Account status from Confirmed, to Suspended etc.

Also, when an account is set up, its default is Unconfirmed, so until the site Administrator confirms the account, the user can not log in, even if they know their Username and Password.

Hope this helps

Many thanks !!!

January 17, 2004 by moni moni

That's the solution !!!