Advertisement
Guest User

Untitled

a guest
Oct 11th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. <?php
  2. require_once('lnc/recaptchalib.php');
  3. require_once('lnc/db.config.php');
  4.  
  5. $user_ip = $_SERVER['REMOTE_ADDR'];
  6. $username = isset($_POST['username']) ? trim($_POST['username']) : '';
  7. $password = isset($_POST['password']) ? trim($_POST['password']) : '';
  8. $password2 = isset($_POST['password2']) ? trim($_POST['password2']) : '';
  9. $email = isset($_POST['email']) ? trim($_POST['email']) : '';
  10. $errors = array();
  11. $success = false;
  12.  
  13. // Process the POST data.
  14. if(isset($_POST) && !empty($_POST)){
  15. // Validate user name.
  16. if(empty($username)){
  17. $errors[] = 'Please provide a user name.';
  18. }else if(strlen($username) < 3 || strlen($username) > 16){
  19. $errors[] = 'User name must be between 3 and 16 characters in length.';
  20. }else if(ctype_alnum($username) === false){
  21. $errors[] = 'User name must consist of numbers and letters only.';
  22. }else{
  23.  
  24. // Check if username already exists in the database.
  25. $sql = 'SELECT szUserID FROM TACCOUNT WHERE szUserID = :szUserID';
  26. $qry = $tglob->prepare($sql);
  27. $qry->bindValue(':szUserID', $username);
  28. $res = $qry->execute();
  29. if(!$res){
  30. $errors[] = 'Failed to determine if this username already exists in the database.';
  31. }elseif($qry->fetch(PDO::FETCH_ASSOC)){
  32. $errors[] = 'User name already exists, please choose a different user name.';
  33. }
  34. }
  35.  
  36. // Validate user password.
  37. if(empty($password)){
  38. $errors[] = 'Please provide a password.';
  39. }else if(strlen($password) < 3 || strlen($password) > 16){
  40. $errors[] = 'Password must be between 3 and 16 characters in length.';
  41. }else if($password != $password2){
  42. $errors[] = 'Passwords do not match.';
  43. }
  44.  
  45. // Validate reCAPTCHA. This is to prevent someone botting account creation.
  46. $username;$password;$password2;$captcha;
  47. if(isset($_POST['username'])){
  48. $username=$_POST['username'];
  49. }
  50. if(isset($_POST['password'])){
  51. $password=$_POST['password'];
  52. }
  53. if(isset($_POST['password2'])){
  54. $password2=$_POST['password2'];
  55. }
  56. if(isset($_POST['email'])){
  57. $email=$_POST['email'];
  58. }
  59. if(isset($_POST['g-recaptcha-response'])){
  60. $captcha=$_POST['g-recaptcha-response'];
  61. }
  62. if(!$captcha){
  63. $errors[] = 'Failed captcha authentication.';
  64. }
  65. $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LfjKRUUAAAAAG_yCxzZX1SnZd_HCjwFRpaFJ1-5&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
  66. if($response==false)
  67. {
  68. $errors[] = 'Stop spamming our site!';
  69. }
  70.  
  71. // Persist the new account to the database if no previous errors occured.
  72. if(count($errors) == 0){
  73. $password = ($password);
  74. $sql = 'INSERT INTO TACCOUNT
  75. (szUserID,szPasswd,bCheck,szEmail)
  76. VALUES (:szUserID, :szPasswd, :bCheck, :szEmail)';
  77. $qry = $tglob->prepare($sql);
  78. $qry->bindValue(':szUserID', $username);
  79. $qry->bindValue(':szPasswd', $password);
  80. $qry->bindValue(':bCheck', 1, PDO::PARAM_INT);
  81. $qry->bindValue(':szEmail', $email);
  82. $res = $qry->execute();
  83. if($res){
  84. $success = htmlentities("Account {$username} successfully created!");
  85. }else{
  86. // This means the insert statement is probably not valid for your database. Fix the query or fix your database, your choice ;)
  87. $errors[] = 'Failed to create a new account, please try again later';
  88. }
  89. }
  90. }
  91. // Determine which view to show.
  92. if($success === false){
  93. require_once('register.view.php');
  94. }else{
  95. require_once('success.view.php');
  96. }
  97. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement