Guest User

Untitled

a guest
Jan 5th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. <?php
  2. require_once('recaptchalib.config.php');
  3. require_once('recaptchalib.php');
  4. require_once('db.config.php');
  5.  
  6. $user_ip = $_SERVER['REMOTE_ADDR'];
  7. $username = isset($_POST['username']) ? mssql_escape_string(trim($_POST['username'])) : '';
  8. $password = isset($_POST['password']) ? mssql_escape_string(trim($_POST['password'])) : '';
  9. $password2 = isset($_POST['password2']) ? mssql_escape_string(trim($_POST['password2'])) : '';
  10. $admin = 0;
  11. $errors = array();
  12. $success = false;
  13. if(isset($_POST) && !empty($_POST)){
  14. require_once('db.php');
  15.  
  16. // Validate user name.
  17. $result = @mssql_query("SELECT UserID FROM PS_UserData.dbo.Users_Master WHERE UserID = '{$username}'") or die('Failed to verify is the provided user named already exists.');
  18. if(empty($username)){
  19. $errors[] = 'Please provide a user name.';
  20. }else if(strlen($username) < 3 || strlen($username) > 16){
  21. $errors[] = 'User name must be between 3 and 16 characters in length.';
  22. }else if(ctype_alnum($username) === false){
  23. $errors[] = 'User name must consist of numbers and letters only.';
  24. }else if(mssql_num_rows($result)){
  25. $errors[] = 'User name already exists, please choose a different user name.';
  26. }
  27. // Validate user password.
  28. if(empty($password)){
  29. $errors[] = 'Please provide a password.';
  30. }else if(strlen($password) < 3 || strlen($password) > 20){
  31. $errors[] = 'Password must be between 3 and 20 characters in length.';
  32. }else if($password != $password2){
  33. $errors[] = 'Passwords do not match.';
  34. }
  35. // Validate reCAPTCHA. This is to prevent someone botting account creation.
  36. $response = recaptcha_check_answer($recaptcha_private_key,$_SERVER['REMOTE_ADDR'],$_POST['recaptcha_challenge_field'],$_POST['recaptcha_response_field']);
  37. if(!$response->is_valid){
  38. if($response->error == 'incorrect-captcha-sol'){
  39. $errors['recaptcha'] = 'Incorrect answer to reCAPTCHA';
  40. }else{
  41. $errors['recaptcha'] = $response->error;
  42. }
  43. }
  44. // Persist the new account to the database if no previous errors occured.
  45. if(count($errors) == 0){
  46. /* prepare the statement resource */
  47. $stmt=mssql_init("Create_Shaiya_Account", $conn);
  48.  
  49. /* now bind the parameters to it */
  50. mssql_bind($stmt, "@UserID", $username, SQLVARCHAR, FALSE);
  51. mssql_bind($stmt, "@Pw", $password, SQLVARCHAR, FALSE);
  52. mssql_bind($stmt, "@Administrator", $admin, SQLINT4, FALSE);
  53.  
  54. /* now execute the procedure */
  55. $result = mssql_execute($stmt);
  56. // Remove the @ symbol here to see what the SQL error message is when running the above query in $sql.
  57. if($result = @mssql_execute ($stmt)){
  58. $success = "Account {$username} successfully created!";
  59. }else{
  60. // This means the insert statement is probably not valid for your database. Fix the query or fix your database, your choice ;)
  61. $errors[] = 'Failed to create a new account, please try again later';
  62. }
  63. }
  64. }
  65. // Determine which view to show.
  66. if($success === false){
  67. require_once('register.view.php');
  68. }else{
  69. require_once('success.view.php');
  70. }
  71. ?>
Add Comment
Please, Sign In to add comment