Print Page | Close Window

what’s wrong with this code..?

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=2745
Printed Date: 29 March 2026 at 7:40pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: what’s wrong with this code..?
Posted By: fernan82
Subject: what’s wrong with this code..?
Date Posted: 15 May 2003 at 2:49pm

I use this code for my site login script (it's basically -borg-'s code slightly modified)......... The problem is that i got a JavaScript pop up at the end of the code (text in red) and all the code is getting executed but those lines so i don't get no pop up when the password is incorrect. Any ideas why this is happening? here's the code:

'If a username has been entered check that the password is correct
If NOT strUsername = "" Then


 'Read the various forums from the database
 'Initalise the strSQL variable with an SQL statement to query the database
 strSQL = "SELECT tblAuthor.Password, tblAuthor.Salt, tblAuthor.Author_ID, tblAuthor.User_code "
 strSQL = strSQL & "FROM tblAuthor "
 strSQL = strSQL & "WHERE tblAuthor.Username = '" & strUsername & "';"

 'Query the database
 rsCommon.Open strSQL, adoCon

 'If the query has returned a value to the recordset then check the password is correct

 If NOT rsCommon.EOF Then


  'Encrypt password so we can check it against the encypted password in the database
  'Read in the salt
  strPassword = strPassword & rsCommon("Salt")

  'Encrypt the entered password
  strPassword = HashEncode(strPassword)


  'Check the encrypted password is correct, if it is get the user ID and set a cookie

  If strPassword = rsCommon("Password") Then


   'Read in the users ID number and whether they want to be automactically logged in when they return to the forum
   lngUserID = CLng(rsCommon("Author_ID"))
   strUserCode = rsCommon("User_code")

   'Write a cookie with the User ID number so the user logged in throughout the forum
   'Write the cookie with the name Forum containing the value UserID number
   Response.Cookies("Forum")("UID") = strUserCode
   If CBool(Request.Form("ActiveUsers")) = False Then
    Response.Cookies("Forum")("Hide") = True
   Else
    Response.Cookies("Forum")("Hide") = False
   End If


   'If the user has selected to be remebered when they next login then set the expiry date for the cookie for 1 year
   If blnAutoLogin = True Then

    'Set the expiry date for 1 year
    'If no expiry date is set the cookie is deleted from the users system 20 minutes after they leave the forum
    Response.Cookies("Forum").Expires = DateAdd("yyyy", 1, Now())
   End If

   'Reset Server Objects
   rsCommon.Close
   Set rsCommon = Nothing
   adoCon.Close
   Set adoCon = Nothing
   Response.Redirect strNewRedir

         End If

 End If

'Popup alert if username or password is invalid
Response.Write("<script  language=""JavaScript"">")
Response.Write("alert('Invalid Username And/Or Password');")
Response.Write("</script>")

End If



-------------
FeRnAN
http://www.danasoft.com/">



Replies:
Posted By: farrukh
Date Posted: 15 May 2003 at 3:14pm
Originally posted by fernan82 fernan82 wrote:

'Popup alert if username or password is invalid
Response.Write("<script  language=""JavaScript"">")
Response.Write("alert('Invalid Username And/Or Password');")
Response.Write("</script>")


make asp tag close
%>

<script  language="JavaScript">
window.alert("Invalid Username And/Or Password")
</script>

<%
      asp code here
%>

check out the view source of the page and see what is actually written in your code. I will clear your more.

-------------
i have collected some nice avatars (37) and smileys (227) here you can download
http://www24.brinkster.com/webmastertool/download.html


Posted By: fernan82
Date Posted: 15 May 2003 at 4:25pm

I tried that before and it didn't work neither

right after that code i got this code:

'Reset Server Objects
Set rsCommon = Nothing
adoCon.Close
Set adoCon = Nothing

If blnGuest Then

'Redirect to the page where this script was loaded from
If strNewRedir = "" Then strNewRedir = Request.ServerVariables("URL")
If strNewRedir <> Request.ServerVariables("URL") Then Response.Redirect strNewRedir

That way after the login or log off the user is redirected to the same page they were at (i got this script included in all pages on my site)...so i can't really look at the source cuz i get redirected right away...

If i comment out the later code it will display the javascript pop up but then the script wouldn't work correctly, so the actual problem i guess is that the redirect is being executed before the javascript.........how can that happen if the javascript is first..???



-------------
FeRnAN
http://www.danasoft.com/">


Posted By: fernan82
Date Posted: 15 May 2003 at 4:52pm
I figure the server doesn't start spitting out the html and javascript until it has procesed all the ASP code, so it executes the Response.Redirect command before it even spits any html or javascript out........ what can i do about it?

-------------
FeRnAN
http://www.danasoft.com/">


Posted By: fernan82
Date Posted: 15 May 2003 at 5:40pm

I've tried everything,

i made a new file with just the javascript pop up and a <% Response.Redirect %> line and change my login script to redirect to that page but it'll also execute the asp line and not the javascript, i tried making an .htm file with just the javascript and include it using include file and it didn't work neither, it executes the Response.Redirect commands but it doesn't spit out any javascript or html to the browser...



-------------
FeRnAN
http://www.danasoft.com/">


Posted By: Gullanian
Date Posted: 16 May 2003 at 5:05am

Can you copy and paste the error?

Have you got any HTML before that code?  Even an <HTML> tag?



Posted By: Mart
Date Posted: 16 May 2003 at 9:17am

'Popup alert if username or password is invalid
Response.Write("<script  language=""JavaScript"">")
Response.Write("alert('Invalid Username And/Or Password');")

Response.Write("window.location=""page.asp"";")
Response.Write("</script>")

Uses javascript to redirect the user...



Posted By: fernan82
Date Posted: 16 May 2003 at 2:44pm
Originally posted by Gullanian Gullanian wrote:

Can you copy and paste the error?

Have you got any HTML before that code?  Even an <HTML> tag?

I can't cuz there's no error, basicly the ASP script is running on the background and is not spitting out any HTML or JavaScript at all, and yes i do have an <html> tag on the page and also i got quite a bit of JavaScript on the page even before any ASP code but it's not being sent to the browser, it executes the ASP before it starts spitting out HTML, so since i got a Response.Redirect on the code it just redirects me to the next page without even spitting any html out....

Originally posted by Mart Mart wrote:

'Popup alert if username or password is invalid
Response.Write("<script  language=""JavaScript"">")
Response.Write("alert('Invalid Username And/Or Password');")

Response.Write("window.location=""page.asp"";")
Response.Write("</script>")

Uses javascript to redirect the user...

Thanks, that does works, the reason i didn't wanted to do it that way is because if the user's browser doesn't support Java or is not enabled then it'll stay on the empty page, i guess i'm gonna have to use one of those "Click here if you're not redirected" link but that wouldn't look too good (at least i don't like it like that) but i guess i'm gonna have to settle with that for now........

Anyone knows if that's a limitation on ASP or if there's something that can be done about it??

Thanks.



-------------
FeRnAN
http://www.danasoft.com/">


Posted By: Awangku
Date Posted: 19 May 2003 at 2:08am

If you really have a look at the codes, you will see that you will always get the Invalid Username/Password message when you enter something in the username box.

Put the word ELSE before the Response.Write line. Something like below:

If NOT strUsername = "" Then
  .....
Else
  Response.Write("<script language=""JavaScript"">")
  .....
End If

See whether it works or not.



Posted By: fernan82
Date Posted: 19 May 2003 at 5:17pm
Originally posted by Awangku Awangku wrote:

If you really have a look at the codes, you will see that you will always get the Invalid Username/Password message when you enter something in the username box.

Put the word ELSE before the Response.Write line. Something like below:

If NOT strUsername = "" Then
  .....
Else
  Response.Write("<script language=""JavaScript"">")
  .....
End If

See whether it works or not.

Negative, if you really have a look at the code there's a response.redirect before the javascript so if the password is correct the user will be redirected before it gets to the javascript, the If NOT strUsername = "" Then only verifies that the form has been entered so if i do as you said then it would bring that pop-up all the time!



-------------
FeRnAN
http://www.danasoft.com/">



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net