• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 184
  • Last Modified:

Seeion name and validation

Hello all,

I'have a login page that looks up a database table and if the username and password is correct, it lets users further to the other web pages.  In each web page's header, I have the below, so that if the user attempts to open a page without logging in, the user is forwared to the login page.
<%
If Session("name") = false Then
    Response.Redirect("loginpage.asp")
End If
%>

I also have other few pages that only the supervisor can enter.

<%
If Session("name") <> "userx" Then
    Response.Redirect("loginpage.asp")
End If
%>

That was working fine for me. But now, I need three users; userx, usery and userz to be able to view these few pages.  How can I modify the above code so that all three users can view the page?

I tried the below knowing that it is daft to do so, and of course it didnt work.  What is the correct syntax please?
<%
If Session("name") <> "userx,usery,userz" Then
    Response.Redirect("loginpage.asp")
End If
%>

Thanks

0
bedevi
Asked:
bedevi
2 Solutions
 
TimCotteeCommented:
Hi bedevi,

If Session("Name") <> "userx" And Session("Name") <> "usery" And Session("Name ") <> "userz" Then

Though this will get difficult to maintain in the long run, this is where it is worthwhile linking this to a database and using that to maintain your users.

Tim Cottee
0
 
GENTPCommented:
As above stated, using a database of users would be the 'best' way to go on this.

Sticking with the way you're going about things, I'd create a function to validate everything. Do a seperate if statement for each user (this way you could quick add/remove a line (but you need to redeploy each time still) and simply return a boolean value.

Then all you need to do is:
if validateUser(Session("name")) then
        response.redirect("loginpage.asp")
else
        'load page and do everything you want to
end if
0
 
bedeviAuthor Commented:
I did this on a first come first server basis I hope it is fair.
Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now