Wrox Programmer Forums
|
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2006, 03:10 PM
Registered User
 
Join Date: Dec 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with login function please

Hi guys

I've been using the excellent Beginning Dreamweaver MX book to help with a website. In the book it helps you do a neat thing with Dreamweaver's login behaviour. Using this ASP code, a user can login and be presented with information on the same page that wasn't there prior to logging in.

<%
    MM_authorizedUsers="Admin, Customer"
    If Session("MM_Username") <> "" Then
      If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
         (InStr(1,MM_authorizedUsers,Session("MM_UserAuthor ization"))>=1) Then
%>
Hello! <%
          End if
         End if
         %>


I was wondering how to modify this so that the opposite can be done, so that the user can see some text, such as 'Login', and once the user has logged in the 'Login' text will disappear. Once the user has logged out, the 'Login' text will reappear on the page.

I hope I've clearly relayed my problem! I would appreciate any help with this issue. Thank you.

 
Old December 11th, 2006, 03:25 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is the same thing... an "if" block can do something when the "if" condition is true, or do some other action when it is false.

In pseudo code:

If UserIsProperlyLogged On
  Show normal stuff
else
  Show login stuff
End if

Make sense? In the pseudo code the UserIsProperlyLogged represents your logic that checks if the user is logged on.



Woody Z
http://www.learntoprogramnow.com
 
Old December 11th, 2006, 03:58 PM
Registered User
 
Join Date: Dec 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi
Thanks for your response. I understand your point but I'm not sure how to apply it to my problem. I'm new to ASP and it's a tricky language to get to grips with.

 
Old December 11th, 2006, 04:04 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

woody's pseudo code is as "easy" as it gets; pseudo code is what programmers use to lay out their code in plain english so that they can get an idea of what their application needs to do.

This code is not how I would do this but you can get the basic concept.

If Session("UserName") = "" then
Response.Write("Please Login <a href='./login.asp'>here</a>!")
else
Response.Write("Hello " & Session("UserName"))
End if

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old December 11th, 2006, 05:19 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Kamraniac,

Glad you like the book. I think the answers you got in this thread should get you started. In addition, you can also add a simple Else clause to the code you already have:

If Session("MM_Username") <> "" Then
If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
        (InStr(1,MM_authorizedUsers,Session("MM_UserAuthor ization"))>=1) Then
%>[/b] Hello! <%
End if
Else
Response.Write("You're not logged in")
End if

Basically, the Else fires when the opposite of the If is true....

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Bruch Nr. 1 g-moll Op. 26: Vorspiel (Allegro moderato) by Mendelssohn & Bruch (Track 4 from the album: Violinkonzerte - Hoelscher) What's This?
 
Old December 11th, 2006, 05:55 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Imar
 Hi Kamraniac,

Glad you like the book. I think the answers you got in this thread should get you started. In additional, you can also add a simple Else clause to the code you already have:

If Session("MM_Username") <> "" Then
If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
        (InStr(1,MM_authorizedUsers,Session("MM_UserAuthor ization"))>=1) Then
%>[/b] Hello! <%
End if
Else
Response.Write("You're not logged in")
End if

Basically, the Else fires when the opposite of the If is true....

Hope this helps,

Imar
This is very close, but there are two conditions here, and the second condition can also result in a "not logged in" state. I would suggest moving both conditions to a function that returns true if the user is okay to enter the site (authenticated and authorized) and false otherwise.

Woody Z
http://www.learntoprogramnow.com
 
Old December 11th, 2006, 05:59 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You can presume, unless the developer goes to great lengths, that there are only 2 states for a user: Logged On and Not Logged On in which case Imar's example works fine.

-------------------------
I will only tell you how to do it, not do it for you.
Unless, of course, you want to hire me to do work for you.

^^Thats my signature
 
Old December 11th, 2006, 06:03 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
quote:This is very close, but there are two conditions here, and the second condition can also result in a "not logged in" state.
No, it can't.

This is Dreamweaver generated code which always looks a bit awkward. Basically, this is user and role checking in one block of code.

Session("MM_Username") holds the username while Session("MM_UserAuthorization") holds the user's role.

If the username is empty, the user is not logged on. However, even if you don't have any roles, you can still be logged in. So, the nested if is only for roles checking....:
Code:
If Session("MM_Username") <> "" Then
  If (false Or CStr(Session("MM_UserAuthorization"))="") Or _
        (InStr(1,MM_authorizedUsers,Session("MM_UserAuthorization"))>=1) Then
%> Hello! <%
  Else
    Response.Write("Sorry, you're not an Admin or a Customer")
  End if
Else
  Response.Write("You're not logged in")
End if
Obviously, moving code to a function to abstract the complexity is a great idea, but not something that Dreamweaver offers out of the box....

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: Small Time Shot Away by Massive Attack (Track 7 from the album: 100th Window) What's This?
 
Old December 11th, 2006, 06:15 PM
Registered User
 
Join Date: Dec 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you so much woodyz, dparsons and Imar! You've been a great help. :)






Similar Threads
Thread Thread Starter Forum Replies Last Post
login script: user can't hit "return" for login dmerrill Java Basics 13 July 14th, 2006 07:25 PM
login failed for user nt authority\anonymous login rj1406 Classic ASP Databases 1 October 24th, 2004 09:15 AM
I can't find bugs in my Login function. (User.cs) kaz VS.NET 2002/2003 5 December 7th, 2003 05:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.