Advertisement
Guest User

Untitled

a guest
May 10th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. <?php
  2. if (!empty($_POST['username']) && !empty($_POST['password']) && !empty($_POST['email']) && !empty($_POST['secret'])) {
  3.  
  4. if ($_POST['secret'] != 'vwevqiwubevoqwyev12930v1273vwoievbqwoeivgdfgdyeiVBYWOVEQOPB') {
  5. die('?');
  6. }
  7.  
  8. ########################
  9. $db_ip = "";
  10. $db_user = "";
  11. $db_password = "";
  12. $db_auth = "auth";
  13. ########################
  14.  
  15.  
  16. $username = htmlspecialchars($_POST['username']);
  17. $password = htmlspecialchars($_POST['password']);
  18. $email = htmlspecialchars($_POST['email']);
  19.  
  20.  
  21.  
  22. echo register_user($username, $email, $password);
  23. }
  24.  
  25.  
  26. function connect($ip, $user, $password, $database){
  27. $con = mysqli_connect($ip, $user, $password, $database) or die('try again in some minutes, please');
  28. if (!$con)
  29. printf("Connect failed: %s\n", mysqli_connect_error());
  30. else
  31. return $con;
  32. }
  33.  
  34. function encrypt($username, $password)
  35. {
  36. $password = sha1(strtoupper($username) . ":" . strtoupper($password));
  37. $password = strtoupper($password);
  38. return $password;
  39. }
  40.  
  41. function check_user_exist($username){
  42. global $db_ip, $db_user, $db_password, $db_auth;
  43. $con = connect($db_ip, $db_user, $db_password, $db_auth);
  44. $stmt = $con->prepare("SELECT * FROM account WHERE `username`=?");
  45. $stmt->bind_param("s", $username);
  46. $stmt->execute();
  47. $stmt->store_result();
  48. return $stmt->num_rows;
  49. $stmt->close();
  50. $con->close();
  51. }
  52.  
  53. function check_email_exist($email){
  54. global $db_ip, $db_user, $db_password, $db_auth;
  55. $con = connect($db_ip, $db_user, $db_password, $db_auth);
  56. $stmt = $con->prepare("SELECT * FROM account WHERE `email`=?");
  57. $stmt->bind_param("s",$email);
  58. $stmt->execute();
  59. $stmt->store_result();
  60. return $stmt->num_rows;
  61. $stmt->close();
  62. $con->close();
  63. }
  64.  
  65. function register_user($username, $email, $password){
  66.  
  67. $new_password = encrypt($username,$password);
  68.  
  69. $sql = "INSERT INTO `account` (`username`, `sha_pass_hash`, `email`) VALUES (?,?,?)";
  70.  
  71. global $db_ip, $db_user, $db_password, $db_auth;
  72.  
  73. $con = connect($db_ip, $db_user, $db_password, $db_auth);
  74.  
  75. if (check_user_exist($username) > 0)
  76. return 1;
  77. if (check_email_exist($email) > 0)
  78. return 2;
  79.  
  80. if (check_user_exist($username) == 0 && check_email_exist($email) == 0) {
  81. if ($stmt = $con->prepare($sql)) {
  82. $stmt->bind_param("sss", $username, $new_password, $email);
  83. $stmt->execute();
  84. $stmt->close();
  85. return 3;
  86. }
  87. }
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement