Click to See Complete Forum and Search --> : a simple login for admin section
Hey,
I'm hoping to create a very simple login section, for one administrator (not multiple users)
would like to know your thoughts/advice on this?
buntine
01-30-2004, 10:18 AM
All you have to do is create a HTML form with two text boxes. One named 'user' and one named 'pass'.
The form will be submitted back to the same page and checked against 2 pre-defined variables. If the username and password are correct, a session variable will be set and the user will be redirected to the member page. Otherwise, an error message will be displayed.
Excerpt:
Option Explicit
Response.buffer = true
Dim user, pass
Dim att_user, att_pass
user = "admin"
pass = "default"
att_user = request.form("user")
att_pass = request.form("pass")
with response
if att_user <> user or att_pass <> pass then
.write("Error...")
.end
else
Session("user") = "admin"
.redirect("somepage.asp")
end if
end with
This is a very basic script. Most login modules require a database, but, you only need one user so a DB is not required here.
Regards,
Andrew Buntine.
thanks very much,
luckily for me today my boss is leaving now so I get to to leave to,
take care have a nice weekend I will have a good look at the code on on monday. :)
Bullschmidt
02-05-2004, 03:36 AM
And here is something I previously put together about creating a login capability. It just adds a little more about the overall concept to Andrew's great answer.
Perhaps have a login page that asks the user for his username and password. And whatever page that posts to (which could be the same page for a self posting form) tests these fields against what is in the database, sets the username and userlevel session variables accordingly, and then redirects to the proper page - i.e. back to the login page if the password is wrong (perhaps with a JavaScript popup saying wrong username/password combination) or to the main menu page if the password is correct:
Session("UserName") = objRS("UserName")
Session("UserLevel") = objRS("UserLevel")
Response.Redirect "mainmenu.asp"
Then you can use If Then's or Select Case on each page to control whether a user is allowed to actually be there and whether particular links of where a user can go actually show up.
If (Session("UserLevel") <> "Admin") And (Session("UserLevel") <> "Regular") Then
Response.Redirect "login.asp"
End If