Closed Thread Icon

Topic awaiting preservation: Login Problem (ASP) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12965" title="Pages that link to Topic awaiting preservation: Login Problem (ASP)" rel="nofollow" >Topic awaiting preservation: Login Problem (ASP)\

 
Author Thread
Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 11-03-2003 01:55

Hi, guys. How are you?
I am making login system using ASP and Access database.
It is sort of working but I wanna fix couple of points.
When I load page, each time Javascript alert box pops up. But I wanna it when user click *login* without entering username or password.
Here is my code:

code:
<%@LANGUAGE = VBScript%>
<%


Dim username,password
username = Request.Form("username")
password = Request.Form("password")
If username = "" OR password = "" Then
%>
<script>
alert("hey, enter something")
</script>

<%
Else
Dim cn,sql
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& Server.MapPath("database.mdb") &";Persist Security Info=False"
Set sql = cn.Execute("SELECT * FROM login WHERE field1 LIKE '" & username & "' AND field2 LIKE '" & password & "'")
If sql.EOF Then
%>
<script>
alert("Hey, you wrong!")
</script>
<%
else
Session("username") = username
Response.Write("Thank you, " & username & " welcome!")
End if
End if
%>
<style>



I know why alert box always pops up when I load page. But I cannot think of how to make this stop.
Please help1!

Hiroki Kozai

Hiroki
Paranoid (IV) Inmate

From: NZ
Insane since: Dec 2002

posted posted 11-03-2003 03:12
code:
Dim username,password
username = Request.Form("username")
password = Request.Form("password")
If username <> "" AND password <> "" Then

Dim cn,sql
Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& Server.MapPath("database.mdb") &";Persist Security Info=False"
Set sql = cn.Execute("SELECT * FROM login WHERE field1 LIKE '" & username & "' AND field2 LIKE '" & password & "'")
If sql.EOF Then


%>
<script>
alert("Hey, you wrong, mate!")
</script>
<%


Else
Session("username") = username
Response.Write("Thank you, " & username & " welcome!")
End if
End if



I changed my code like above.
I don't understand why I get alert box when I load page.
Cuz I said:

code:
If username <> "" AND password <> "" Then



Alert box is supposed to be shown only when username or password filed is empty.
Do you know what I mean?
Hmm...

Hiroki Kozai

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 11-03-2003 03:31

Hiroki: As is, it seems that you're using the same script to display and process the form. If you separate the display and the process, you wouldn't have the kind of problem you describe. If that's not that, you should check what Request.Form("username") and Request.Form("password") really returns, and if it's always some string and not the NULL value which is different from ""

A little off topic, but I wonder if you code in ASP for your own pleasure of because you're asked to. Cause all the others inmates seems to code in PHP, so you'd get more insight if you let fall ASP for PHP. Not to mention that PHP is completely free and have a huuuuge community.

Cheers,

Mathieu "POÏ" HENRI

« BackwardsOnwards »

Show Forum Drop Down Menu