Jump to content

Working on Login Code, Need Advice


Eivo

Recommended Posts

Ok, I am trying to get a login page working and I'm running into errors and such. I'm using ASP (classic) and JScript. Here is what I have...

<%var connectionObject = new ActiveXObject("ADODB.Connection");var connectionString = "Provider=sqloledb; Data Source=mssql08.1and1.com,1433; Initial Catalog=db186589768; User Id=*****; Password=*****;"connectionObject.Open(connectionString);				var recordset = new ActiveXObject("ADODB.Recordset");var find = "SELECT * FROM security WHERE username LIKE '" + Request.Form("usernameFM") + "'"recordset.Open(find,connectionObject);var user = new String(Request.Form("usernameFM"))var pass = new String(Request.Form("passwordFM"))var userRS = new String(recordset("username"))var passRS = new String(recordset("password"))<!-- This part is just for making sure that my form data and DB data are correct, shouldn't even see it if it matches. -->Response.Write("<div style=\"color:#FFFFFF;\">");Response.Write(recordset("username") + "<br/>");Response.Write(user + "<br/>");Response.Write(recordset("password") + "<br/>");Response.Write(pass + "<br/>");Response.Write("</div>");<!-- Ok, that part is over -->if (userRS == user && passRS == pass){Response.Redirect("controlpanel.asp");}else{Response.Write("<div style=\"color:#FFFFFF;\">");Response.Write("Sorry, the username or password you entered was incorrect, <a href=\"login.asp\">please click here to return to the log in page</a>");Response.Write("</div>");}recordset.Close;connectionObject.Close;connectionObject = null;%>

The behavior I get from the code is like this...Correct User name & Correct Password = Error-Free, Failed LoginCorrect User name & Incorrect Password = Error-Free, Failed LoginIncorrect User name & Correct Password = Error PageIncorrect User name & Incorrect Password = Error PageHere is the Error from the Error pages...

ADODB.Field error '800a0bcd'Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record./mfvfd/check.asp, line 134
Line 134 is: var userRS = new String(recordset("username"))I have a few ideas of what I am doing wrong, but I haven't been able to get it to work still. Any help would be greatly appreciated. Thanks in advance. :)
Link to comment
Share on other sites

I am going to try "recordset.MoveFirst" and see if that works. But before I go, do Session variables carry over from page to page or is it just for the page it is declared in?

Link to comment
Share on other sites

Wow, I replied to this yesterday but the server must have eaten it.Like it9888 said, you need to check for EOF. recordset.EOF will be true if there are no results in the recordset (if the username was not found). So after you open the recordset check if recordset.EOF is true before you try to use it.As for the part where the login is failing but you aren't getting an error, what do you mean by failing? Do you see the message you have displaying there, or does it redirect to the controlpanel page and then have a problem there? Because this is pretty straightforward:if (userRS == user && passRS == pass)If those are equivalent, then it succeeds, if not then it fails. So if that is failing, then they aren't matching. If that's the case and you think they should match, then print out the values for all of those to see what is being compared.And sessions do move from page to page.

Link to comment
Share on other sites

By "Failed" I get my message as if the user/pass are incorrect. In none of the scenarios do I get redirected to controlpanel.asp, that's why I am confused. I checked the database several times and even copy from and pasted to the login but it still had the same results. I think that it has something to do with the user putting in the info and it being converted to a string, but I can't find any info about that in regards to ASP anywhere. For example, Username == Username =False(String)_____(Not String)But I have both as strings so that shouldn't be the case right? I dunno why it's giving me this. I have a temporary fix in place right now, but I need to figure this out. :)Thanks for the help :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...