Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.60 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. function check_email_address($email) {
  5. // First, we check that there's one @ symbol,
  6. // and that the lengths are right.
  7. if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
  8. // Email invalid because wrong number of characters
  9. // in one section or wrong number of @ symbols.
  10. return false;
  11. }
  12. // Split it into sections to make life easier
  13. $email_array = explode("@", $email);
  14. $local_array = explode(".", $email_array[0]);
  15. for ($i = 0; $i < sizeof($local_array); $i++) {
  16. if
  17. (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&
  18. ?'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
  19. $local_array[$i])) {
  20. return false;
  21. }
  22. }
  23. // Check if domain is IP. If not,
  24. // it should be valid domain name
  25. if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
  26. $domain_array = explode(".", $email_array[1]);
  27. if (sizeof($domain_array) < 2) {
  28. return false; // Not enough parts to domain
  29. }
  30. for ($i = 0; $i < sizeof($domain_array); $i++) {
  31. if
  32. (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
  33. ?([A-Za-z0-9]+))$",
  34. $domain_array[$i])) {
  35. return false;
  36. }
  37. }
  38. }
  39. return true;
  40. }
  41.  
  42. require_once('config.php');
  43.  
  44. $username = trim(strtolower($_POST['name']));
  45. $username = mysql_escape_string($username);
  46.  
  47. $email = trim(strtolower($_POST['email']));
  48. $email = mysql_escape_string($email);
  49.  
  50. $pass = trim(strtolower($_POST['pass']));
  51. $pass = mysql_escape_string($pass);
  52.  
  53. $question = trim(strtolower($_POST['question']));
  54. $question = mysql_escape_string($question);
  55.  
  56. $pass2 = trim(strtolower($_POST['pass2']));
  57. $pass2 = mysql_escape_string($pass2);
  58.  
  59. $answer = trim(strtolower($_POST['answer']));
  60. $answer = mysql_escape_string($answer);
  61.  
  62. $noerrors = true;
  63.  
  64.  
  65.  
  66. if($username)
  67. {
  68.  
  69. $query = "SELECT Username FROM accounts WHERE Username = '$username'";
  70. $result = mysql_query($query) or die(mysql_error());
  71.  
  72. if(strlen($username) > 0 && mysql_num_rows($result) > 0)
  73. {
  74. ?>
  75. <script>
  76. $.jGrowl("<b><u>Failed</u></b><br>Your Username is already taken.", {
  77. theme: "error",
  78. speed: "fast",
  79. });</script>
  80. <?php
  81. $noerrors = false;
  82. }
  83. } else {
  84. ?>
  85. <script>
  86. $.jGrowl("<b><u>Failed</u></b><br>Your Username is already taken.", {
  87. theme: "error",
  88. speed: "fast",
  89. });</script>
  90. <?php
  91. $noerrors = false;
  92. }
  93.  
  94. if($email)
  95. {
  96. if(!check_email_address($email))
  97. {
  98. ?>
  99. <script>
  100. $.jGrowl("<b><u>Failed</u></b><br>Invaild Email Address Format.", {
  101. theme: "error",
  102. speed: "fast",
  103. });</script>
  104. <?php
  105. $noerrors = false;
  106. }
  107. } else {
  108. ?>
  109. <script>
  110. $.jGrowl("<b><u>Failed</u></b><br>Invaild Email Address Format.", {
  111. theme: "error",
  112. speed: "fast",
  113. });</script>
  114. <?php
  115. $noerrors = false;
  116. }
  117.  
  118. if($pass)
  119. {
  120. if(strlen($pass) < 4)
  121. {
  122. ?>
  123. <script>
  124. $.jGrowl("<b><u>Failed</u></b><br>Password only english letters and numbers,lenght of 4 to 12.", {
  125. theme: "error",
  126. speed: "fast",
  127. });</script>
  128. <?php
  129. $noerrors = false;
  130. }
  131. } else {
  132. ?>
  133. <script>
  134. $.jGrowl("<b><u>Failed</u></b><br>Password only english letters and numbers,lenght of 4 to 12.", {
  135. theme: "error",
  136. speed: "fast",
  137. });</script>
  138. <?php
  139. $noerrors = false;
  140. }
  141.  
  142. if($pass != $pass)
  143. {
  144. ?>
  145. <script>
  146. $.jGrowl("<b><u>Failed</u></b><br>Confirm Password don't match.", {
  147. theme: "error",
  148. speed: "fast",
  149. });</script>
  150. <?php
  151. $noerrors = false;
  152.  
  153. }
  154.  
  155. if($answer)
  156. {
  157. if (preg_match('/[^A-Za-z0-9]/', $answer) && !strlen($answer) > 3 && !strlen($answer) < 32)
  158. {
  159. ?>
  160. <script>
  161. $.jGrowl("<b><u>Failed</u></b><br>Answer only english letters and numbers,lenght of 4 to 32.", {
  162. theme: "error",
  163. speed: "fast",
  164. });</script>
  165. <?php
  166. $noerrors = false;
  167. }
  168. } else {
  169. ?>
  170. <script>
  171. $.jGrowl("<b><u>Failed</u></b><br>Answer only english letters and numbers,lenght of 4 to 32.", {
  172. theme: "error",
  173. speed: "fast",
  174. });</script>
  175. <?php
  176. $noerrors = false;
  177. }
  178.  
  179.  
  180. if($noerrors)
  181. {
  182.  
  183. $ins=mysql_query('INSERT INTO accounts(Username,Password,IP,Email,Question,answer) VALUES ("'.$username.'","'.$pass.'","'.$_SERVER['REMOTE_ADDR'].'", "'.$email.'", "'.$question.'", "'.$answer.'")') or die(mysql_error());
  184. if($ins)
  185. {
  186.  
  187. $result1 = "SELECT * FROM `accounts` WHERE username='$username' and password='$pass'";
  188.  
  189. $query = mysql_query($result1);
  190. $sql2 = mysql_fetch_assoc($query);
  191. if ($count==1){
  192. $logued=1;
  193.  
  194. $_SESSION["acc"]=$sql2['Username'];
  195. $_SESSION["uid"]=$sql2['EntityID'];
  196. echo 'all_ok';
  197. }
  198.  
  199. echo "all_ok";
  200. }
  201.  
  202.  
  203. }
  204.  
  205. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement