-
June 10th, 2012, 09:26 PM
#1
HELP! :( Login not working
Please I really need somebody to help me..
Here's my code.. what should I do to make it work?..
Code:
<script type = "text/javascript">
<%
Dim Conn, sql, rs
If IsObject( Session( "Conn" ) ) Then
Set Conn = Session( "Conn" )
Else
set Conn = server.createobject("adodb.connection")
constr = "Provider=sqloledb;Data Source=datasource;" & _
"Initial Catalog=catalog;User Id=id;Password=password;"
Conn.open constr
Set Session( "Conn" ) = Conn
End If
%>
var count = 2;
function validate() {
var un = document.myform.username.value;
var pw = document.myform.pword.value;
var valid = false;
var unArray = <%=rs("EmpID")%>;
var pwArray = <%=rs("Password")%>;
<%
sql = "SELECT password FROM "CarInfo" WHERE EmpID = '"&EmpID&"'
Set rs = Server.CreateObject( "ADODB.Recordset" )
rs.Open sql, Conn
rs.MoveFirst()
While Not rs.EOF
%>
for (var i=0; i <unArray.length; i++) {
if ((un == unArray) && (pw == pwArray)) {
valid = true;
break;
}
}
if (valid) {
alert ("Login was successful");
window.location = "car.html";
return false;
}
var t = " tries";
if (count == 1) {t = " try"}
if (count >= 1) {
alert ("Invalid username and/or password. You have " + count + t + " left.");
document.myform.username.value = "";
document.myform.pword.value = "";
setTimeout("document.myform.username.focus()", 25);
setTimeout("document.myform.username.select()", 25);
count --;
}
else {
alert ("Still incorrect! You have no more tries left!");
document.myform.username.value = "No more tries allowed!";
document.myform.pword.value = "";
document.myform.username.disabled = true;
document.myform.pword.disabled = true;
return false;
}
}
</script>
<body background="back.jpg">
<form name = "myform">
<h1><center> Monde Nissin Corporation </center></h1>
<h2><center> Car Benefit Monitoring System </center></h2>
<br/><br/><br/><p> <Center> Enter Username and Password </center> </p> <br/>
<p><center> USER NAME <input type="text" name="username"> <br/><br/> PASSWORD <input type="password" name="pword"><br/><br/>
<input type="button" value="Login" name="Submit" onclick= "validate()">
</center> </p>
</form>
</body>
please.. somebody help me..
Last edited by PeejAvery; June 10th, 2012 at 10:13 PM.
Reason: Added code tags
-
June 11th, 2012, 04:38 AM
#2
Re: HELP! :( Login not working
Your ASP code is incomplete. You have a SQL query:
Code:
sql = "SELECT password FROM "CarInfo" WHERE EmpID = '"&EmpID&"'
But you haven't defined what EmpID is, plus you've used single quotes around CarInfo - these should be doubled up.
Secondly you have a While loop:
that never gets closed.
Third, you are referencing embedded ASP variables before they've actually been defined, i.e.
Code:
var unArray = <%=rs("EmpID")%>;
but it's only later in the page where you actually define what rs is.
Finally once you've validated the user, you really should set some type of session variable that is then checked on each page to ensure they've been validated, otherwise what's stopping them going directly to the CAR.HTML page?
-
June 12th, 2012, 05:08 AM
#3
Re: HELP! :( Login not working
HI the cat.. first of all, thank you for your reply..
sql = "SELECT password FROM "CarInfo" WHERE EmpID = '"&EmpID&"' is supposed to be
sql = "SELECT password FROM "CarInfo" WHERE EmpID = '"&username&"'
and.. should I remove the while loop?.. what should I replace?..
also.. what should I do with this?..
Third, you are referencing embedded ASP variables before they've actually been defined, i.e.
Code:
var unArray = <%=rs("EmpID")%>;
but it's only later in the page where you actually define what rs is.
i'm so sorry for my lack of knowledge..
-
June 12th, 2012, 05:09 AM
#4
Re: HELP! :( Login not working
please help me..
-
June 12th, 2012, 07:37 AM
#5
Re: HELP! :( Login not working
Much as I like ASP, I would suggest looking at .NET as there are some out-of-the-box password controls you can add: http://www.asp.net/web-forms/videos/...rship-provider
If you want to persevere with ASP then use some template code like this: http://www.evolt.org/node/28652
Notice that it also includes the ASP code (in protectedpage.asp) that will need to be added to all the subsequent pages to check to see if they are authenticated:
Code:
<%
Response.Expires = -1000 'Makes the browser not cache this page
Response.Buffer = True 'Buffers the content so our Response.Redirect will work
If Session("UserLoggedIn") <> "true" Then
Response.Redirect("login.asp")
End If
%>
You'll need to change the subroutine CheckLogin, to something like this:
Code:
Sub CheckLogin
Dim Conn, rs
set Conn = server.createobject("adodb.connection")
constr = "Provider=sqloledb;Data Source=datasource;" & _
"Initial Catalog=catalog;User Id=id;Password=password;"
Set rs = Server.CreateObject( "ADODB.Recordset" )
rs.Open sql, Conn
Session("UserLoggedIn") = "false"
Do While Not rs.EOF
If Request.Form("username") = rs("EmpID") And Request.Form("userpwd") = rs("Password") Then
Session("UserLoggedIn") = "true"
Exit Do
End If
rs.MoveNext
Loop
rs.Close
Conn.Close
If Session("UserLoggedIn") = "true" Then
Response.Redirect "protectedpage.asp"
Else
Response.Write("Login Failed.<br><br>")
ShowLogin
End If
End Sub
I haven't tested it but it should work. It won't give you your 2 attempts at trying, but then a simple page refresh would workaround the 2 attempt limit anyway; you're better off using either a cookie to cache the number of login attempts or record these back to your SQL database.
-
June 12th, 2012, 09:42 AM
#6
Re: HELP! :( Login not working
Thank you so much.. I will try this one..
-
June 12th, 2012, 07:10 PM
#7
Re: HELP! :( Login not working
I have another question.. where should I put this code?
[code:]
function validate()
for my
[code:]
<input type="submit" value="Login" name="Submit" onclick= "validate()">
-
June 12th, 2012, 07:51 PM
#8
Re: HELP! :( Login not working
I already tried the codes.. the Interface appeared, but when I tried to put the correct username and password, nothing happens. the same with wrong username and password..
-
June 13th, 2012, 03:44 AM
#9
Re: HELP! :( Login not working
If you use the example from the link that I sent you then you don't need to call validate onclick.
Or are you persevering with your code?
You should probably run a quick check that your ASP / SQL Server code is working correctly. A page something like this TEST.ASP should do the trick:
Code:
<html>
<head><title>Test reading SQL</title></head>
<body>
EmpIDs and passwords from the SQL Server:<br/>
<%
set Conn = server.createobject("adodb.connection")
constr = "Provider=sqloledb;Data Source=datasource;" & _
"Initial Catalog=catalog;User Id=id;Password=password;"
Set rs = Server.CreateObject( "ADODB.Recordset" )
rs.Open sql, Conn
Response.Write "<table><tr><th>EmpID</th><th>Password</th></tr>"
Do While Not rs.EOF
Response.Write "<tr><td>" & rs("EmpID") & "</td><td>" & rs("Password") & "</td></tr>"
rs.MoveNext
Loop
rs.Close
Conn.Close
Response.Write "</table>"
%>
</body>
</html>
But DELETE THIS PAGE AFTERWARDS! If this doesn't work then you've got issues either to do with your connection to the SQL, the user id/ pwd for SQL, ASP maybe not enabled etc. so you're then into a debugging IIS / SQL cycle....
-
June 15th, 2012, 01:53 AM
#10
Re: HELP! :( Login not working
i tried this test.asp but it's not working on me..
am i doing it right?..
Data Source = I created a datasource at control panel, administrative tools, datasources, etc..
Initial Catalog = database name
user id = user
password = password..
-
June 15th, 2012, 06:07 AM
#11
Re: HELP! :( Login not working
I've never created a database that way and I'm not sure that's the right way to do it!
Why not just use a tool like Microsoft SQL Server Management Studio to connect and create the database, then create the EmpID and Password fields and populate them.
Although ASP is old technology, it's easy to modify an ASP script to be a VBScript and test it, so I created a database called "datasource" and a table called "CarInfo" and made some fields: "EmpID" and "Password" and then added some data, opened a command prompt and created a TEST.VBS file which says:
Code:
strConn = "Provider=SQLOLEDB;SERVER=server\sqlserver;UID=sa;PWD=password;"
strSQL = "SELECT [EmpID],[Password] FROM [datasource].[dbo].[CarInfo]"
Const adOpenStatic = 3
Const adLockReadOnly = 1
Const adCmdText = &H0001
set conn = CreateObject("ADODB.Connection")
set rs = CreateObject("ADODB.Recordset")
conn.Open strConn
rs.Open strSQL , conn, adOpenStatic, adLockReadOnly, adCmdText
Do While Not rs.EOF
WScript.Echo rs("EmpID") & VBTab & rs("Password")
rs.MoveNext
Loop
rs.Close
Conn.Close
Then ran CSCRIPT TEST.VBS and it listed all the records I'd entered. I would expect the equivalent ASP code to do the same thing (however I'm not in a position to test that).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|