Sample Code for asp user registration:
Database Design:
Table Name: userinfo
Field name type/length description
Id: User id
Username text/16 username
Password text/32 MD5 32-bit encryption
Addtime time date registration time
The Code is as follows:
<%
'Asp tutorial user registration example
'Http: // www.asp.org.cn
Dim db, conn, myconn
Db = "asporgcn. mdb" 'database file relative path
Set Conn = Server. CreateObject ("ADODB. Connection") 'create an object instance
Myconn = "Provider = Microsoft. Jet. OLEDB.4.0; Data Source =" & Server. MapPath ("" & db &"")
Conn. Open MyConn
If request ("submit") <> "" then', click submit.
Username = request ("username ")
Password = request ("password ")
Password2 = request ("password2 ")
If password <> password2 then
Response. write ("<script> alert ('wrong password entered twice '); window. history. back (); </script> ")
Response. end () 'stops running
End if
Set rs = server. CreateObject ("adodb. recordset ")
SQL = "select count (0) from userinfo where username = '" & username &"'"
Rs. open SQL, conn, 1, 1
If rs (0)> 0 then': determines whether the user name has been registered.
Response. write ("<script> alert ('user name already exists '); window. history. back (); </script> ")
Response. end () 'stops running
Else
'Response. write "insert into userinfo (username, password) values ('" & username & "', '" & password &"')"
Conn.exe cute ("insert into userinfo ([username], [password]) values ('" & username & "', '" & password &"')") 'The registration is completed after the database is added. The password is the reserved keyword in ACCESS. If the reserved keywords are enclosed in [], no errors will occur.
Response. write ("<script> alert ('registration successful! '); Window. history. back (); </script> ")
End if
Rs. close
Set rs = nothing, you must remember to close and release the RS after use. Otherwise, the server resources will be occupied. During the ASP program interview, this 1.1 must be remembered.
End if
Conn. close 'close the connection,
Set conn = nothing is very important to release the memory, otherwise it will occupy a lot of server resources.
%>
<Html>
<Head>
<Title> User Registration case </title>
<META content = "User Registration case tutorial compiled by ASP in China. Http://www.asp.org.cn "name = description>
</Head>
<Body>
<Form id = "form1" name = "form1" method = "post" action = "index. asp">
<Table width = "400" border = "1">
<Tr>
<Td> User name: </td>
<Td> <label>
<Input name = "username" type = "text" id = "username" size = "16" maxlength = "16"/>
</Label> </td>
</Tr>
<Tr>
<Td> password: </td>
<Td> <input name = "password" type = "password" id = "password" size = "16" maxlength = "16"/> </td>
</Tr>
<Tr>
<Td> Confirm Password: </td>
<Td> <input name = "password2" type = "password" id = "password2" size = "16" maxlength = "16"/> </td>
</Tr>
<Tr>
<Td colspan = "2"> <label>
<Input type = "submit" name = "Submit" value = "submit"/>
</Label> </td>
</Tr>
</Table>
</Form>
</Body>
</Html>