View Single Post
  #20 (permalink)  
Old Dec 29th, 2005, 03:05
benbramz benbramz is offline
Highly Reputable Member
Join Date: May 2005
Location: U.K
Age: 21
Posts: 739
Thanks: 0
Thanked 0 Times in 0 Posts
Re: some type of member login/register system

heres the asp version:

again, we have the form, with the 4 fields....

HTML: Select all
<form name="form1" method="post" action="add_user.asp">
    <input name="username" type="text" id="username" value="username">
    <input name="password" type="password" id="password" value="password">
    <input name="reminder" type="text" id="reminder" value="reminder">
    <input name="email" type="text" id="email" value="email">
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" name="Reset" value="Reset">
</form>
simple.
Next up we have add_user.asp which will add the users details into the database. this example is set for using access as the database type, so beware! as the db can just be downloaded. move to a host that offers sql db Lucid!
anyway, here.
Code: Select all
dim conn, add
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("database.mdb"))
Set add = Server.CreateObject("ADODB.Recordset")
add.Open "SELECT * FROM users", conn, 2, 2 
add.AddNew 
add("username") = request.form("username")
add("password") = request.form("password")
add("reminder") = request.form("reminder")
add("email") = request.form("email")
add.Update
add.close
set conn = nothing
response.write("you have just made an account!")
this example is assuming you have a database, named database.mdb - with a table called users, with the columns username, password, reminder and email. you can change them here:-
add("THIS-IS-WHERE-YOU-WOULD-CHANGE")
next, you need a form to check the users details.
HTML: Select all
<form name="login" method="post" action="check_user.asp">
  <input name="textfield" type="text" value="username">
  <input name="textfield" type="password" value="password">
  <input name="login" type="submit" id="login" value="login">
</form>
ta daaa!
now, for user checking
Code: Select all
dim conn, login
Set conn = Server.CreateObject("ADODB.connion")
conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("database.mdb"))
Set login = Server.CreateObject("ADODB.Recordset")
login.Open "SELECT * FROM users where username='" & request.form("username") & "' and password='"& request.form("password") & "'" , conn, 3, 1, 1 
if login.recordcount <> 1 then
response.write "wrong username / password!"
else
session("username")= login("username")
session("userID")= login("ID")
end if
login.close
set conn = nothing

response.Redirect("member_page_perhaps")
thats pretty much the end of a basic tutorial on asp login...

if you wanted to have a member page, and only allow member to see it, you could add this, to your page.
Code: Select all
 <%
 if session("username") > "" then
 %>
 <!-- add you html content here.....-->
 <%
 else
 response.write "you have to be a member"
 end if
 %>
if you wanted to display the users username somewhere, just place <%=session("username")%>

remeber, that using an access db to store account info is not a good idea. as it can be downloaded. one step would be to encrypt the password, but that only adds a small amount of protection. using a sql database is the most secure way...
Reply With Quote