Guest User

Untitled

a guest
Jan 17th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. <?php
  2. $con = mysql_connect('localhost', 'root', '') OR die("Error: ".mysql_error());
  3. mysql_select_db('maplestory', $con) OR die("Error: ".mysql_error());
  4.  
  5. function protect($string){
  6. $string = mysql_real_escape_string($string);
  7. $string = strip_tags($string);
  8. $string = addslashes($string);
  9. return $string;
  10. }
  11. if(!$_POST['submit']) {
  12. echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" align=\"center\">\n";
  13. echo "<form method=\"post\" action=\"".$self."\">\n";
  14. echo "<tr><td colspan=\"2\" align=\"center\" bgcolor=\"#333333\"><font color=\"#ffffff\">Registration</font></td></tr>\n";
  15. echo "<tr><td>Username:</td><td><input type=\"text\" name=\"username\"></td></tr>\n";
  16. echo "<tr><td>Password:</td><td><input type=\"password\" name=\"password\"></td></tr>\n";
  17. echo "<tr><td>Confirm:</td><td><input type=\"password\" name=\"passconf\"></td></tr>\n";
  18. echo "<tr><td align=\"left\"><input type=\"submit\" name=\"submit\" value=\"Done\"></form></td></tr>\n";
  19. echo "</form></table>\n";
  20. } else {
  21. $username = protect($_POST['username']);
  22. $password = sha1($_POST['password']);
  23. $confirm = sha1($_POST['passconf']);
  24.  
  25. $errors = array();
  26.  
  27. if(!$username) {
  28. $errors[] = "Username is not defined!";
  29. }
  30.  
  31. if(!$password) {
  32. $errors[] = "Password is not defined!";
  33. }
  34.  
  35. if($password) {
  36. if(!$confirm) {
  37. $errors[] = "Confirmation password is not defined!";
  38. }
  39. }
  40.  
  41. if($username) {
  42. if(!ctype_alnum($username)) {
  43. $errors[] = "Username can only contain numbers and letters!";
  44. }
  45.  
  46. $range = range(1,12);
  47. if(!in_array(strlen($username),$range)) {
  48. $errors[] = "Username must be between 1 and 12 characters!";
  49. }
  50. }
  51.  
  52. if($password && $confirm) {
  53. if($password != $confirm) {
  54. $errors[] = "Passwords do not match!";
  55. }
  56. }
  57.  
  58. if($username) {
  59. $sql = "SELECT * FROM `accounts` WHERE `name`='".$username."'";
  60. $res = mysql_query($sql) or die(mysql_error());
  61. if(mysql_num_rows($res) > 0) {
  62. $errors[] = "The username you supplied is already in use!";
  63. }
  64. }
  65.  
  66. if(count($errors) > 0) {
  67. foreach($errors AS $error) {
  68. echo $error . "<br>\n";
  69. }
  70. } else {
  71. $sql1 = "INSERT INTO `accounts`
  72. (`name`,`password`)
  73. VALUES ('".$username."','".$password."')";
  74. $res4 = mysql_query($sql1) or die(mysql_error());
  75. echo "<font align=\"center\"><b>You have successfully registered!</b></font>";
  76. }
  77. }
  78. ?>
Add Comment
Please, Sign In to add comment