PDA

View Full Version : ASP Login


sagat
01-23-2004, 11:58 PM
I have just created a login screen and i am using a POST action. When i run the code, it says "method is not allowed". "The requested method POST is not allowed for the URL /securityloginrespond.asp" where am i going wrong? is there a of subsituting the Post action or using an altogether different method?

<html><head>
<title>securitylogin.asp</title>
</head><body bgcolor="#FFFFFF">
<form action="securityloginrespond.asp" method="POST">
Sign In Page:<p>
Name -&gt; <input NAME="userName" size="20"><br>
Password -&gt; <input NAME="userPassword" size="20"><br>
<input type="submit"><input type="reset">
</form></body></html>

fractalvibes
01-24-2004, 04:33 AM
It is probably encountering an error in securityloginrespond.asp.

What does that script look like?

sagat
01-24-2004, 02:50 PM
Here is the code. Please can u tell me where i am going wrong? thanks:

<html><head>
<title>securitylogin.asp</title>
</head><body bgcolor="#FFFFFF">
<form action="securityloginrespond.asp" method="POST">
Sign In Page:<p>
Name -&gt; <input NAME="userName" size="20"><br>
Password -&gt; <input NAME="userPassword" size="20"><br>
<input type="submit"><input type="reset">
</form></body></html>
<%
myname=request.form("username")
mypassword=request.form("userpassword")
set conntemp=server.createobject("adodb.connection")

dbname="/phpdev5/www/customsecurity.mdb"
myconnect="PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=customerlogin"
myconnect=myconnect & server.mappath(dbname)& "c:/phpdev5/www/customsecurity.mdb"

conntemp.Open myconnect

sqltemp="select * from users where user='"
sqltemp=sqltemp & myname & "'"
set rstemp=conntemp.execute(SQLTemp)
If rstemp.eof then%>
we don't have a user named <%=Myname%> on file!<br>
Try <A href='securitylogin.asp'>Logging in</a> again
<%response.end
end if
If rstemp("Password")=mypassword then
session("name")=rstemp("user")
session("securitylevel")=rstemp("securitylevel")
response.write "Security Level=" & session("securitylevel")
else%>
Password Unrecognized<br>
Try <A href='securitylogin.asp'>Logging in</a> again
<%response.end
end if
rstemp.close
conntemp.close
set rstemp=nothing
set conntemp=nothing
%>

raf
01-24-2004, 03:47 PM
sounds more like a permission-problem to me.

Are you sure that the site is correctly configured inside IIS? Do other pages in that directory work correct ?

sagat
01-24-2004, 04:43 PM
actually i am using apache installed on my home PC. i dont have IIS. I replaced POST with GET and the error was gone. What i am trying tp do is created a basic ASP login script with a simple access database that has username and password. When the user logs in, they are redirected to a website.

sagat
01-24-2004, 05:11 PM
I realise that there are many login scripts on the net. i came close to getting one work:

<%
'Save the entered username and password
Username = Request.Form("txtUsername")
Password = Request.Form("txtPassword")

'Build connection with database
set conn = server.CreateObject ("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath ("c:\phpdev5\www\login screen.mdb")
set rs = server.CreateObject ("ADODB.Recordset")
'Open record with entered username
rs.Open "SELECT * FROM user where username='"& Username &"'", conn, 1

'If there is no record with the entered username, close connection
'and go back to login with QueryString
If rs.recordcount = 0 then
rs.close
conn.close
set rs=nothing
set conn=nothing
Response.Redirect("asplogin.asp?login=namefailed")
end if

'If entered password is right, close connection and open mainpage
if rs("password") = Password then
Session("name") = rs("fullname")
rs.Close
conn.Close
set rs=nothing
set conn=nothing
'If entered password is wrong, close connection
'and return to login with QueryString
else
rs.Close
conn.Close
set rs=nothing
set conn=nothing
Response.Redirect("asplogin.asp?login=passfailed")
end if

%>

Please can someone spot the errors in this sript? thanks

sagat
01-24-2004, 05:39 PM
<% Response.Buffer = true %>
<%
Session("C:\phpdev5\www\login screen.mdb") = "Path to your database"
If Request.Form("btnLogin") = "Login" AND Request.Form("txtName") <> "" _
AND Request.Form("txtPassword") <> "" Then

'-- Declare your variables
Dim DataConnection, cmdDC, RecordSet
Dim RecordToEdit, Updated, strUserName, strPassword

strUserName = Request.Form("txtName")
strPassword = Request.Form("txtPassword")

'-- Create object and open database
Set DataConnection = Server.CreateObject("ADODB.Connection")
DataConnection.Open "DRIVER={Microsoft Access Driver (*.mdb)};" & _
"DBQ=" & Session("C:\phpdev5\www\login screen.mdb") & ";"

Set cmdDC = Server.CreateObject("ADODB.Command")
cmdDC.ActiveConnection = DataConnection

'-- default SQL
SQL = "SELECT * FROM Login Screen"

If Request.Form("txtName") <> "" Then
SQL = "SELECT Login Screen.* FROM Login Screen " & _
"WHERE Login Screen.userID='" & strUserName& _
"' AND Login Screen.Password ='" & strPassword & "'"
End If

cmdDC.CommandText = SQL
Set RecordSet = Server.CreateObject("ADODB.Recordset")

'-- Cursor Type, Lock Type
'-- ForwardOnly 0 - ReadOnly 1
'-- KeySet 1 - Pessimistic 2
'-- Dynamic 2 - Optimistic 3
'-- Static 3 - BatchOptimistic 4
RecordSet.Open cmdDC, , 0, 2
...
If Not RecordSet.EOF Then
Dim struserLevel
struserLevel = RecordSet.Fields("userLevel")
Session("userLevel") = struserLevel
Else
'The user was not validated...
'Take them to a page which tells them they were not validated...
Response.Redirect "register.asp"
End If
End If
%>

<form action="index2.asp" method="post">
<% If Session("userLevel") > 0 AND Request.Form("btnLogin") = "Login" _
AND Request.Form("txtName") <> "" AND _
Request.Form("txtPassword") <> "" Then
Response.write("<b>" & Request.Form("txtName"))
Response.write("</b> is logged on.<BR>")
Response.write("User Access Level is: ")
Response.write(RecordSet.Fields("userLevel") & "<BR>")
End If
%>

<table border="1" cellpadding="5" cellspacing="0">
<tr>
<td>User Name:</td>
<td><input type="text" name="txtName" size="40" ></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="txtPassword" size="40" value=""></td>
</tr>
</table>
<p>
<input type="submit" name="btnLogin" value="Login">
</form>

<%

Hi guys also whats wrong with this script? i have done all i could.

raf
01-24-2004, 09:53 PM
ignore. see next post

raf
01-24-2004, 09:53 PM
Originally posted by sagat
actually i am using apache installed on my home PC. i dont have IISInteresting. Can you tell me how? Did you use the chilisoft package? Because Apache can't serve ASP's unless you use perl as scripting language (which you don't) or have a special package (like the one from chilisoft) to first port your ASP's (which is basically having them automatically rewriten with perl as scriptinglanguage).

Originally posted by sagat
I replaced POST with GET and the error was gone.
Realy? Because i still see request.form everywhere in your code.
If you use GET, then the formdata is sent to the webserver inside the querystring, and then you need to use request.querystring to acces the form-data.

sagat
01-24-2004, 10:42 PM
Thanks. i imagined that i needed to use the chilisoft package. Unfortunately i dont have an online web account but rather i am working from home. So i just installed the basic Apache package which came with PHP.The GET does not work actually. Another option for me would be to try these scripts at university. They probably have ASP installed. Do u have any good ASP login script sites? thanx

raf
01-24-2004, 11:57 PM
you don't realy need Apache (not if your not running a productionserver in a high-load environment). If it is just for development-use, then you can download microsofts PWS and install that.

http://coveryourasp.com/PWS.asp

For loginscripts --> try http://www.hotscripts.com/ASP/Tips_and_Tutorials/User_Authentication/index.html
or Googl for it.

whammy
01-25-2004, 04:12 AM
sagat.... what operating system are you using?

If it's Microsoft, then our forum members can hook you up with some IIS quick.

<edit>I don't work for Bill, but I like C#</edit>

:p

sagat
01-25-2004, 05:47 PM
Hi, i am using Windows XP Pro i tried to download IIS on my PC but it was not successful (it kept saying locate files i386 on service pack 1, which i think is already installed). Where can i download it on the net? Thnks

ghell
01-25-2004, 06:27 PM
if u have a winXPpro disk you have iis5.1 on it

all newish versions of windows have iis or pws on them (iis on nt based ones, pws on 9x based ones) so:

winserver2003 has iis6.0
winxp pro has iis5.1
winxphome has a version of pws
... continue going back in time and lowering the version numbers :p

sagat
01-25-2004, 09:50 PM
thanks it is working now figured it out.silly me doh!!!!