Advertisement
Guest User

Untitled

a guest
Jan 21st, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. <?php
  2. $mysql_host = "127.0.0.1";
  3. $mysql_user = "root";
  4. $mysql_pass = "pass";
  5. $mysql_db = "hii";
  6.  
  7. $action = "";
  8.  
  9. if (isset($_GET['action']))
  10. $action = $_GET["action"];
  11. ?>
  12.  
  13. <?php
  14.  
  15. function udb_hash($pass)
  16. {
  17. $length = strlen($pass);
  18. $s1 = 1;
  19. $s2 = 0;
  20. for($n = 0; $n < $length; $n++)
  21. {
  22. $s1 = ($s1 + $pass[$n]) % 65521;
  23. $s2 = ($s2 + $s1) % 65521;
  24. }
  25. $wy = ($s2 << 16) + $s1;
  26. return $wy;
  27.  
  28. }
  29.  
  30. ?>
  31.  
  32. <h1>Register Placeholder</h1>
  33.  
  34. <form name="register" action="register.php?action=doregister" method="post">
  35. <table>
  36. <tr>
  37.  
  38. <td>SA-MP Name:</td>
  39. <td><input type="text" name="username" /></td>
  40. </tr>
  41.  
  42. <tr>
  43. <td>Password:</td>
  44. <td><input type="password" name="password" />
  45. </tr>
  46.  
  47. <tr>
  48. <td>Email:</td>
  49. <td><input type="text" name="email" />
  50. </tr>
  51.  
  52. <tr>
  53. <td colspan="2">
  54. <center><input type="submit" value="Register" style="width: 200px;" /></center>
  55. </td>
  56. </tr>
  57. </table>
  58. </form>
  59.  
  60. <?php
  61. if (strcmp($action, "doregister") == 0)
  62. {
  63. $con = mysql_connect($mysql_host, $mysql_user, $mysql_pass);
  64.  
  65. if (!$con)
  66. {
  67. die(mysql_error());
  68. }
  69.  
  70. mysql_select_db($mysql_db, $con);
  71.  
  72. $username = $_POST['username'];
  73. $password_raw = $_POST['password'];
  74. $password = udb_hash($password_raw);
  75. $email = $_POST['email'];
  76.  
  77. $result = mysql_query("SELECT * FROM accounts WHERE username='$username'", $con);
  78.  
  79. if (mysql_num_rows($result) != 0)
  80. {
  81. die("An account already exists with that username.");
  82. }
  83.  
  84. if (strlen($username) > 24)
  85. {
  86. die("Username is too large.");
  87. }
  88.  
  89. mysql_query("INSERT INTO accounts (username, password, email) VALUES ('$username', '$password', '$email')", $con);
  90. echo "Account created.";
  91.  
  92. mysql_close($con);
  93. }
  94. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement