Advertisement
Guest User

Untitled

a guest
Nov 9th, 2017
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. function post_captcha($user_response) {
  2. $fields_string = '';
  3. $fields = array(
  4. 'secret' => '[SECRET KEY KEPT HIDDEN]',
  5. 'response' => $user_response
  6. );
  7. foreach($fields as $key=>$value)
  8. $fields_string .= $key . '=' . $value . '&';
  9. $fields_string = rtrim($fields_string, '&');
  10.  
  11. $ch = curl_init();
  12. curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
  13. curl_setopt($ch, CURLOPT_POST, count($fields));
  14. curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
  15. curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
  16.  
  17. $result = curl_exec($ch);
  18. curl_close($ch);
  19.  
  20. return json_decode($result, true);
  21. }
  22.  
  23. $res = post_captcha($_POST['g-recaptcha-response']);
  24.  
  25. if (!$res['success']) {
  26. $output = "<div class='warning-message'><b>Warning:</b>Complete the RECAPTCHA</div>";
  27. } else {
  28. if(isset($_POST['submit'])) {
  29. $username = strip_tags(stripslashes(mysqli_real_escape_string($conn, $_POST['username'])));
  30. $email = strip_tags(stripslashes(mysqli_real_escape_string($conn, $_POST['email'])));
  31. $password = $_POST['password'];
  32. $conpass = $_POST['conpass'];
  33.  
  34. $passHash = password_hash($password, PASSWORD_BCRYPT);
  35. $usern = str_replace(' ','',$username);
  36. $ip = $_SERVER['REMOTE_ADDR'];
  37.  
  38. if ($conpass !== $password) {
  39. $output = "<div class='warning-message'>Your passwords do not match!</div>";
  40. }
  41.  
  42. $usercheck = $conn->query("SELECT username FROM users WHERE username='$username'");
  43. if ($usercheck->num_rows > 0) {
  44. $output = "<div class='warning-message'>Username is taken</div>";
  45. }
  46. $emailcheck = $conn->query("SELECT email FROM users WHERE email='$email'");
  47. if ($emailcheck->num_rows > 0) {
  48. $msg = "<div class='warning-message'>Email is taken.</div>";
  49. }
  50.  
  51. if(strlen($username) < 3 || strlen($username) > 20){
  52. $output = "<div class='warning-message'><b>Warning:</b> Your Username must be 3-20 characters long.</div>";
  53. }
  54.  
  55. if(strlen($password) < 6 || strlen($password) > 100) {
  56. $output = "<div class='warning-message'><b>Warning:</b> Your Password must be 6-100 characters long.</div>";
  57. }
  58.  
  59. if(empty($output)) {
  60. $query = $conn->query("INSERT INTO `users`(username,email,password,ip,signupdate) VALUES ('$usern','$email','$passHash','$ip',$date')");
  61. if ($query) {
  62. header("Location: ../account/");
  63. }else {
  64. $output = "<div class='warning-message'><b>Warning: </b>An Error has occurred!</div>";
  65. }
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement