Click to See Complete Forum and Search --> : Plz, Need Help....
Wen Lie
May 24th, 2000, 04:37 PM
Dear All,
To all member of Visual Basic World... Hmmm... I'm a beginner at Active Server Pages. I don't know ASP too much, just a little. Hope you guys could help me much. I only know about Visual Basic.
So, would you help me guys ??? Thx a lot if you would.
I've got a problem in calling web page.
For a simple example :
Login and Password Authentication :
Login :___________
Password :___________
When submitting the login and password, I want to check :
If the login and password is invalid, I want to show Invalid.Asp
If the login and password is valid, I want to show MyQuery.Asp
Could anyone tell me how to do this ???
Thx...
BRgds,
Wen Lie
Ianpbaker
May 24th, 2000, 07:29 PM
If you post the information to a check.asp, that checks the username and password and then use the redirect function to take you to either page. Eg.
If blnpassword = true AND blnUsername = true Then
Response.Redirect("MyQuery.Asp")
Else
Response.Redirect("invalid.asp")
End If
Of course you need to check the password and set blnpassword and blnusername. If you need any help with that reply back.
Hope this Helps
Ian
Mark Sreeves
May 24th, 2000, 07:36 PM
If you want to store a user name and password in a database you cn do this:
I posted this for someone else a few weeks ago
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
You need a server that will host Active Server Pages.
I use http://www.ewebcity.com so go there and open an account as a "General User" - don't worry it is free!
Once you've don that you'll need an Access 97 database with fields:
username, password,lastlogin and anything else you want.
call it users.mdb and
put it in a directory called db on your ewebcity site.
copy this code to a file called login.asp
the line:
Conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\rlculver\db\users.mdb"))
needs to contain your account name. Here I've put in rlculver but you'll open an account with a better name than that though!
<%@ Language=VBScript %>
<%
dim username
dim password
dim strSQL
dim rst
username = request("txtUser")
password = request("txtPass")
strSQL = "SELECT * FROM Users WHERE Username = '" & username & "' AND password = '" & password & "';"
Set Conn = Server.CreateObject("ADODB.Connection")
'next line is for on site
Conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\rlculver\db\users.mdb"))
'this line is devmode
'Conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\users.mdb")
Set rst = Conn.Execute(strSQL)
%>
<html>
<head>
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
</head>
<body BGCOLOR="#FFFFFF" BACKGROUND="">
<center><BR><BR>
<%
if rst.eof then
'login fail
%>
<form name="form1" method="post" action="login.asp">
<table width="75%" cellpadding="0" cellspacing="0">
<tr><td><FONT face="Verdana, Arial" color="#000080">This site may only be viewed by authorised users.
<p>Click <a href="mailto:someone@somewhere">here</a> to request a User ID or login below.</font><p><br></td></tr>
<tr><td align="center">
<b>Enter your User ID:</b> <input name="txtUser" size="10" maxlength="10"><BR>
<b>and Password:</b> <input type = password name="txtPass" size="10" maxlength="10">
<input type="submit" value="Login.asp">
</td></tr>
</table>
</form>
<%
else
'login sucessful...
%>
<FONT SIZE="2" FACE="arial, helvetica" color="#0000ff"><b>Login successful</b></font>
<p><b>Good
<%
if (hour(now()) > 0) and (hour(now()) < 12) then%>
Morning
<%else%>
Afternoon
<%end if%>
<%=rst("username")%>
<p><b>You may now proceed.</b>
<p>Click <A HREF="http://rlculvers_pornsite">here</a> to proceed.
<p><br><FONT SIZE="2" FACE="arial, helvetica" size="1" face="Verdana, Arial">Last login on: <%=rst("LastLogin")%></font>
<%
strSQL = "UPDATE Users set LastLogin = '" & Now() & "' WHERE Username = '" & username & "'"
conn.Execute(strsql)
%>
</b>
<%end if
set rst = nothing
set conn = nothing
%>
</CENTER>
</body>
</html>
Ok it need some formatting but it works.
On you own website use put a frame in the default page
index.htm, or default.htm usually
with the source pointing to your ewebcity .....\login.asp page.
a sucessfull login will give access to a set hyperlink. You could change this so the link is stored in the database and each user is sent somewhere else.
to do this change the line:
<p>Click <A HREF="http://www.rlculvers_pornsite">here</a> to proceed.
to
<p>Click <A HREF="<%=hyperlink%>">here</a> to proceed.
where hyperlink is a field name in your database.
Wen Lie
May 25th, 2000, 04:23 PM
Thx guys...
I've just read yours, and I'll try your code.
For Ianpbaker :
Your code :
If blnpassword = true AND blnUsername = true Then
Response.Redirect("MyQuery.Asp")
Else
Response.Redirect("invalid.asp")
End If
What is blnpassword and blnUsername ??? Are they name for Login and password textbox ??? or Just a variable ???
And where should I put your code ??? At my Login.ASP or at another ASP page, the page before showing myquery.asp or invalid.asp ???
For Mark Sreeves :
Thx, I will try first....
And for others :
I still open my mind for other concepts
Thx,
BRgds,
Ianpbaker
May 25th, 2000, 04:46 PM
Hi Wen Lie.
If you use the code Mark kindly gave to check a user name and password from a database. Where he has got the
if rst.eof then
'login fail
%>
Replace that all the way down to the
set rst = nothing
set conn = nothing
with
If rst.eof Then
Response.Redirect("invalid.asp")
Else
Response.Redirect("MyQuery.Asp")
End If
finally make this file in to your login.asp
Hope this makes sense
Ian
[Edited by Ianpbaker on 05-26-2000 at 10:48 AM]
[Edited by Ianpbaker on 05-26-2000 at 10:49 AM]
Wen Lie
May 25th, 2000, 04:56 PM
Thx IanpBarker,
You answer my question... but, how about your blnpassword and blnusername ??? Are they variables or what ???
BRgds,
Mark Sreeves
May 25th, 2000, 05:21 PM
yes blnpassword and blnusername are variables which are set if the password and user name are correct.
here's a simple hardcoded password thingy
username = "Wen Lie" and Password = "Wen Lie"
paste it into wenlogin.asp
<%@ Language=VBScript %>
<%
dim username
dim password
username = request("txtUser")
password = request("txtPass")
if username = "" then
%>
<html>
<head>
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
</head>
<center><BR><BR>
<form name="form1" method="post" action="wenlogin.asp">
<table width="75%" cellpadding="0" cellspacing="0">
<tr><td><FONT face="Verdana, Arial" color="#000080">This site may only be viewed by authorised users.</FONT><p><br> </p></td></tr>
<tr><td align="middle">
<b>Enter your User ID:</b> <input name="txtUser" size="10" maxlength="10"><BR>
<b>and Password:</b> <input type = password name="txtPass" size="10" maxlength="10">
<input type="submit" value="Login">
</td></tr>
</table>
</form>
</center>
</body>
<%
else
if username = "Wen Lie" and Password = "Wen Lie" then
Response.Redirect("MyQuery.Asp")
Else
Response.Redirect("invalid.asp")
End If
end if
%>
</html>
Ianpbaker
May 25th, 2000, 05:24 PM
Theese were just two boolean variables that I used as an example. The way I normally do things is to check both values that are passed and set those variable accordingly. If both are true then both the username and password are correct.
Wen Lie
May 26th, 2000, 09:58 AM
Thx guys...
You both help me a lot.
Wen Lie
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.