Guest User

Untitled

a guest
Mar 6th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. <?php
  2. require_once('recaptchalib.php');
  3. require_once('config.php');
  4. require_once('lib/MYSQLDatabase.inc.php');
  5.  
  6.  
  7. $wusername = $_POST['username'];
  8. $wemail = $_POST['email'];
  9. $wpassword = $_POST['password'];
  10.  
  11. $user_ip = $_SERVER['REMOTE_ADDR'];
  12. $username = isset($_POST['username']) ? mssql_escape_string(trim($_POST['username'])) : '';
  13. $password = isset($_POST['password']) ? mssql_escape_string(trim($_POST['password'])) : '';
  14. $password2 = isset($_POST['password2']) ? mssql_escape_string(trim($_POST['password2'])) : '';
  15. $errors = array();
  16. $success = false;
  17. if(isset($_POST) && !empty($_POST)){
  18. // Connect to MSSQL server - I used an @ symbol to suppress error messages here to avoid giving away the account name in the case of an error.
  19. $conn = @mssql_connect($db_host,$db_user,$db_pass) or die('Failed to connect to MSSQL Server.');
  20. $db = @mssql_select_db('PS_UserData',$conn) or die('Failed to select database PS_UserData.');
  21. // Connect to MySql
  22. $mysqldb = new MYSQLDatabase( $dbusername, $dbpassword, $dbhost, $dbport, $dbname );
  23. if( $mysqldb->Connect() == false ){
  24. $mysqldb->Close();
  25. $errors[] = 'Error connecting to mysql.';
  26. }
  27. if(!is_email($wemail)) {
  28. $errors[] = 'That is not an email';
  29. }else if(!already_reg($mysqldb,$user_ip)) {
  30. $errors[] = 'You already have an account in the wow server';
  31. }else if(!registered($mssqldb,$wemail) {
  32. $errors[] = 'Somehow you have an account on the wow server on that email.';
  33. }
  34. // Validate user name.
  35. $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.');
  36. if(empty($username)){
  37. $errors[] = 'Please provide a user name.';
  38. }else if(strlen($username) < 3 || strlen($username) > 16){
  39. $errors[] = 'User name must be between 3 and 16 characters in length.';
  40. }else if(ctype_alnum($username) === false){
  41. $errors[] = 'User name must consist of numbers and letters only.';
  42. }else if(mssql_num_rows($result)){
  43. $errors[] = 'User name already exists, please choose a different user name.';
  44. }
  45. // Validate user password.
  46. if(empty($password)){
  47. $errors[] = 'Please provide a password.';
  48. }else if(strlen($password) < 3 || strlen($password) > 16){
  49. $errors[] = 'Password must be between 3 and 16 characters in length.';
  50. }else if($password != $password2){
  51. $errors[] = 'Passwords do not match.';
  52. }
  53. // Validate reCAPTCHA. This is to prevent someone botting account creation.
  54. $response = recaptcha_check_answer($recaptcha_private_key,$_SERVER['REMOTE_ADDR'],$_POST['recaptcha_challenge_field'],$_POST['recaptcha_response_field']);
  55. if(!$response->is_valid){
  56. if($response->error == 'incorrect-captcha-sol'){
  57. $errors['recaptcha'] = 'Incorrect answer to reCAPTCHA';
  58. }else{
  59. $errors['recaptcha'] = $response->error;
  60. }
  61. }
  62. // Persist the new account to the database if no previous errors occured.
  63. if(count($errors) == 0){
  64. $sql = "INSERT INTO PS_UserData.dbo.Users_Master
  65. (UserID,Pw,JoinDate,Admin,AdminLevel,UseQueue,Status,Leave,LeaveDate,UserType,Point,EnPassword,UserIp)
  66. VALUES ('{$username}','{$password}',GETDATE(),0,0,0,0,0,GETDATE(),'N',0,'','{$user_ip}')";
  67. // Remove the @ symbol here to see what the SQL error message is when running the above query in $sql.
  68. if($result = @mssql_query($sql)){
  69. $success = "The shaiya account {$username} was successfully created!";
  70. }else{
  71. // This means the insert statement is probably not valid for your database. Fix the query or fix your database, your choice ;)
  72. $errors[] = 'Failed to create a new account for Shaiya, please try again later';
  73. }
  74. $results = $db->Query( "INSERT INTO `accounts` (`login`,`password`,`encrypted_password`,`gm`,`flags`,`banned`,`email`) VALUES('$wusername','$wpassword','sha1( strtoupper( $wusername.":".$wpassword ) )','0','24','0','$wemail')" );
  75. if( $myresult == true)
  76. $succes = "The wow account {$username} was successfully created!";
  77. }else{
  78. $errors[] = 'Failed to create a new account for Wow, please try again later';
  79. }
  80. }
  81. }
  82. // Determine which view to show.
  83. if($success === false || $succes === false){
  84. require_once('register.view.php');
  85. }else{
  86. require_once('success.view.php');
  87. }
  88.  
  89. ?>
Add Comment
Please, Sign In to add comment