Friday, February 24, 2012

Help with Website Password Login

Im new to website programming, and im currently making a website where i have to make a user login screen. The usernames and passwords, are stored in a SQL Database (SQL Server 2000)..

How do i search the database for the username the user enters and checks the password to see if its right? And what program do you recommend to set this up, the easiest? - Thnaksusing asp u can execute the sql queries to do the check.|||Assuming you use ASP you could do something like this:

Username = TRIM(Request.Form("Username"))
Password = TRIM(Request.Form("Password"))

IF Username <> "" AND Password <> "" THEN
SQL = "SELECT Password FROM users WHERE Username = '" & Username & "'"
Database = "myconnectionstring"
Set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.Open Database

Set RS = MyConn.Execute(SQL)
IF RS.EOF THEN
Response.Redirect("keep_out.asp")
ELSE
dbPassword = TRIM(RS("Password"))
IF Password = dbPassword THEN
Session("mysite_login") = True
Response.Redirect("welcome.asp")
ELSE
Response.Redirect("keep_out.asp")
END IF
END IF
END IF|||Thanks Frettmaestro. Im using an ASP webpage made in Frontpage 2002. Ill try the code, but where do i put it? Do i put it in th cade of the Submit (Login) Button? Thanks again.|||Yes, you probably have a loginpage vith a form. You could put the code from my previous post in the top of that file, and have the form post the data to itself. Then in every page that is supposed to be protected you need to include a file that checks if the login-session has been set or not:

check_user.asp (this is the file you include in all protected files):
<%
IF Session("mysite_login") <> True THEN Response.Redirect("keep_out.asp")
%>

And that's it! You have yourself a "secure" page...|||Im sorry, its not working for me. Do you hava a page you made, that uses that same code? If so, could i have the link, so i can see what your doing that im not? thanks

No comments:

Post a Comment