Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('recaptchalib.php');
- require_once('config.php');
- require_once('lib/MYSQLDatabase.inc.php');
- $wusername = $_POST['username'];
- $wemail = $_POST['email'];
- $wpassword = $_POST['password'];
- $user_ip = $_SERVER['REMOTE_ADDR'];
- $username = isset($_POST['username']) ? mssql_escape_string(trim($_POST['username'])) : '';
- $password = isset($_POST['password']) ? mssql_escape_string(trim($_POST['password'])) : '';
- $password2 = isset($_POST['password2']) ? mssql_escape_string(trim($_POST['password2'])) : '';
- $errors = array();
- $success = false;
- if(isset($_POST) && !empty($_POST)){
- // 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.
- $conn = @mssql_connect($db_host,$db_user,$db_pass) or die('Failed to connect to MSSQL Server.');
- $db = @mssql_select_db('PS_UserData',$conn) or die('Failed to select database PS_UserData.');
- // Connect to MySql
- $mysqldb = new MYSQLDatabase( $dbusername, $dbpassword, $dbhost, $dbport, $dbname );
- if( $mysqldb->Connect() == false ){
- $mysqldb->Close();
- $errors[] = 'Error connecting to mysql.';
- }
- if(!is_email($wemail)) {
- $errors[] = 'That is not an email';
- }else if(!already_reg($mysqldb,$user_ip)) {
- $errors[] = 'You already have an account in the wow server';
- }else if(!registered($mssqldb,$wemail) {
- $errors[] = 'Somehow you have an account on the wow server on that email.';
- }
- // Validate user name.
- $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.');
- if(empty($username)){
- $errors[] = 'Please provide a user name.';
- }else if(strlen($username) < 3 || strlen($username) > 16){
- $errors[] = 'User name must be between 3 and 16 characters in length.';
- }else if(ctype_alnum($username) === false){
- $errors[] = 'User name must consist of numbers and letters only.';
- }else if(mssql_num_rows($result)){
- $errors[] = 'User name already exists, please choose a different user name.';
- }
- // Validate user password.
- if(empty($password)){
- $errors[] = 'Please provide a password.';
- }else if(strlen($password) < 3 || strlen($password) > 16){
- $errors[] = 'Password must be between 3 and 16 characters in length.';
- }else if($password != $password2){
- $errors[] = 'Passwords do not match.';
- }
- // Validate reCAPTCHA. This is to prevent someone botting account creation.
- $response = recaptcha_check_answer($recaptcha_private_key,$_SERVER['REMOTE_ADDR'],$_POST['recaptcha_challenge_field'],$_POST['recaptcha_response_field']);
- if(!$response->is_valid){
- if($response->error == 'incorrect-captcha-sol'){
- $errors['recaptcha'] = 'Incorrect answer to reCAPTCHA';
- }else{
- $errors['recaptcha'] = $response->error;
- }
- }
- // Persist the new account to the database if no previous errors occured.
- if(count($errors) == 0){
- $sql = "INSERT INTO PS_UserData.dbo.Users_Master
- (UserID,Pw,JoinDate,Admin,AdminLevel,UseQueue,Status,Leave,LeaveDate,UserType,Point,EnPassword,UserIp)
- VALUES ('{$username}','{$password}',GETDATE(),0,0,0,0,0,GETDATE(),'N',0,'','{$user_ip}')";
- // Remove the @ symbol here to see what the SQL error message is when running the above query in $sql.
- if($result = @mssql_query($sql)){
- $success = "The shaiya account {$username} was successfully created!";
- }else{
- // This means the insert statement is probably not valid for your database. Fix the query or fix your database, your choice ;)
- $errors[] = 'Failed to create a new account for Shaiya, please try again later';
- }
- $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')" );
- if( $myresult == true)
- $succes = "The wow account {$username} was successfully created!";
- }else{
- $errors[] = 'Failed to create a new account for Wow, please try again later';
- }
- }
- }
- // Determine which view to show.
- if($success === false || $succes === false){
- require_once('register.view.php');
- }else{
- require_once('success.view.php');
- }
- ?>
Add Comment
Please, Sign In to add comment