home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / phpmysqlau.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  6.3 KB  |  190 lines

  1. PHP/MySQL User Authentication 
  2.  
  3. This script is a MySQL and PHP user authentication system. It stores everything in a MySQL database. You need to create a database called secretDB. Make a table called users. And add 5 fields to it. Name the 5 fields id, real_name, username, password, email. You can set all of the fileds to char255. If you have any questions, mail me at tyler.longren@midiowa.net 
  4.  
  5.  
  6.  
  7.  
  8. Script Note: 
  9. This script is a MySQL and PHP user authentication system.  It stores everything in a MySQL database.  You need to create a database called secretDB.  Make a table called users.  And add 5 fields to it.  Name the 5 fields id, real_name, username, password, email.  You can set all of the fileds to char255.  If you have any questions, mail me at tyler.longren@midiowa.net 
  10.  
  11.  
  12.  
  13. Name this file adduser.php 
  14. <!---Adduser html form begins here---> 
  15. <html> 
  16. <head><title>User Admin Page : Add a User</title></head> 
  17. <body bgcolor="#ffffff"> 
  18. <table bgcolor=#000000 valign=top align=center border=0><tr><td 
  19. bgcolor=#000000><table cellpadding=4 bgcolor=#ffffff cellspacing=2 border=0> 
  20. <Tr><th>Add a User</th></tr><tr><td> 
  21. <FORM METHOD="post" ACTION="add.php"> 
  22. Real Name: <INPUT TYPE=text MAXLENGTH=70 NAME="real_name" SIZE=20><Br> 
  23. Username: <INPUT TYPE=text MAXLENGTH=70 NAME="username" SIZE=20><Br> 
  24. Password: <Input Type=text Maxlength=70 Name="userpass" Size=10><Br> 
  25. E-mail address: <Input Type=text Maxlength=70 Name="email" Size=20><Br> 
  26. <INPUT TYPE=submit VALUE="Add">  <INPUT type=reset VALUE="Reset Form"></form> 
  27. </tr></td></table></tr></td></table> 
  28. </body> 
  29. </html> 
  30. <!---Adduser html form ends here---> 
  31.  
  32.  
  33.  
  34. Name this file add.php 
  35. <!---Adduser php script begins here---> 
  36. <? 
  37.  
  38. $ID = uniqid( "userID"); 
  39.  
  40. $db = mysql_connect( "localhost", "root", "$password"); 
  41.  
  42. mysql_select_db (secretDB); 
  43.  
  44. $result = mysql_query ( "INSERT INTO users (id, real_name, username, password, email) 
  45.                 VALUES ('$ID', '$real_name', '$username', '$userpass', 
  46. '$email')              "); 
  47. if(!$result) 
  48.    echo  "<b>User not added:</b> ", mysql_error(); 
  49.    exit; 
  50. if($result) 
  51.     { 
  52.     mysql_close($db); 
  53.     print  "User <b>$username</b> added sucessfully!"; 
  54.     } 
  55. else 
  56. print ( "Wrong Password"); 
  57. ?> 
  58. <!---Adduser php script ends here---> 
  59.  
  60.  
  61.  
  62. Name this file deluser.php 
  63. <!---Deleteuser html form begins here---> 
  64. <html> 
  65. <head><title>User Admin Page : Add a User</title></head> 
  66. <body bgcolor="#ffffff"> 
  67. <table bgcolor=#000000 valign=top align=center border=0><tr><td 
  68. bgcolor=#000000><table cellpadding=4 bgcolor=#ffffff cellspacing=2 border=0> 
  69. <Tr><th>Delete a User</th></tr><tr><td> 
  70. <FORM METHOD="post" ACTION="delete.php"> 
  71. Real name: <INPUT TYPE=text MAXLENGTH=70 NAME="real_name" SIZE=20><Br> 
  72. Username: <INPUT TYPE=text MAXLENGTH=70 NAME="username" SIZE=20><Br> 
  73. <br> 
  74. <INPUT TYPE=submit VALUE="Delete">  <INPUT type=reset VALUE="Reset Form"></form> 
  75. </tr></td></table></tr></td></table> 
  76. </body> 
  77. </html> 
  78. <!---Deleteuser html form ends here---> 
  79.  
  80.  
  81.  
  82. Name this file delete.php 
  83. <!---Deleteuser php script begins here---> 
  84. <? 
  85. $connection = mysql_connect( "localhost", "root", "F0AA2pa8") or die ( "Unable to 
  86. connect to MySQL server."); 
  87. mysql_select_db( "secretDB",$connection) 
  88. or die ( "Unable to select requested database."); 
  89. $deleteresult = mysql_query 
  90. ( "DELETE FROM users WHERE real_name = '$real_name' AND username = '$username'"); 
  91.   $result=mysql_query($deleteresult, $connection); 
  92.  $affected_rows=mysql_affected_rows( $connection); 
  93. echo  "<b>$username</b> was probably deleted sucessfully."; 
  94. ?> 
  95. <!---Deleteuser php script ends here---> 
  96.  
  97.  
  98.  
  99. Name this file form.php 
  100. <!---Login html form begins  here---> 
  101. <html> 
  102. <head><title>Login form</title></head> 
  103. <body bgcolor="#ffffff"> 
  104. <form action="login.php" method="post"> 
  105. <table border="0"> 
  106. <tr> 
  107. <td><strong>Username</strong></td> 
  108. <td><input type="text" name="username" size="10" maxsize="50"></td> 
  109. </tr> 
  110. <tr> 
  111. <td><strong>Password</strong></td> 
  112. <td><input type="password" name="password" size="10" maxsize="50"</td> 
  113. </tr> 
  114. <tr> 
  115. <td colspan="2" align="center"> 
  116. <input type="submit" value="Auth me"> 
  117. </td> 
  118. </tr> 
  119. </table> 
  120. </form> 
  121. </body> 
  122. </html> 
  123. <!---Login html form ends here---> 
  124.  
  125.  
  126.  
  127. Name this file login.php 
  128. <!---Login php srcipt begins here---> 
  129. <? 
  130. mysql_connect( "localhost",  "root",  "F0AA2pa8") 
  131.     or die ( "Unable to connect to server."); 
  132. mysql_select_db( "secretDB") 
  133.     or die ( "Unable to select database."); 
  134. $sql =  "SELECT id 
  135.     FROM users 
  136.     WHERE username='$username' and password='$password'"; 
  137. $result = mysql_query($sql) 
  138.     or die ( "Unable to get results."); 
  139. $num = mysql_numrows($result) 
  140.     or die ( "You're not authorized to be here.  If you feel you have recieved this 
  141. message in error, please contact the <a 
  142. href=\"mailto:tyler.longren@midiowa.net\">webmaster</a>"); 
  143. if ($num == 1) { 
  144. echo  "<p>You can be here<br>"; 
  145. echo  "Your username is $username</p>"; 
  146. ?> 
  147. <!---Login php script ends here---> 
  148.  
  149.  
  150.  
  151. Name this file print.php 
  152. <!---View users php script begins here---> 
  153. <?php 
  154. echo  "<html><head><title>User Information</title></head><body 
  155. bgcolor=#ffffff>"; 
  156.  
  157. $connection = mysql_connect( "localhost", "root", "F0AA2pa8") 
  158. or die ( "Unable to connect to MySQL server."); 
  159. $db = mysql_select_db( "secretDB", $connection) or die ( "Unable to select 
  160. database."); 
  161. $sql =  "SELECT id, real_name, username, email 
  162.         FROM users 
  163.         ORDER BY id ASC"; 
  164. $sql_result = mysql_query($sql,$connection) or die ( "Couldn't execute SQL 
  165. query"); 
  166. echo  "<center><b><u>List of users</u></b><br><Br>"; 
  167. echo  "<table bgcolor=#000000><Tr><td bgcolor=#000000><table cellpadding=4 
  168. cellspacing=0 bgcolor=#ffffff>"; echo  "<Tr><th>ID</th><th>Full 
  169. Name</th><th>Username</th><th>E-mail</th></tr>"; while ($row = 
  170. mysql_fetch_array($sql_result)) { $id = $row[ "id"]; 
  171. $real_name = $row[ "real_name"]; 
  172. $username = $row[ "username"]; 
  173. $email = $row[ "email"]; 
  174. echo 
  175. "<tr><td>$id</td><td>$real_name</td><td>$username</td><td> 
  176. <a href=\"mailto:$email\">$email</a></td></tr>"; } 
  177. echo  "</table></td></tr></table>"; 
  178. echo  "</center>"; 
  179. mysql_free_result($sql_result); 
  180. mysql_close($connection); 
  181. echo  "</body></html>"; 
  182. ?> 
  183. <!---View users php script ends here--->
  184.  
  185.