0

I am building a jQuery file to validate user input for login on a wordpress site. I have made functions to check the wordpress database for usernames, emails, and passwords. I have the functions working perfectly for usernames and emails, however with the password function I get a 500 internal server error. The only thing I can think of that would be causing this would be my trying to include three files from wordpress. I have to use the class-phpass.php to check the passwords as the passwords are hashed and then stored into the database. The class-phpass.php file has a function called CheckPassword which compares a hashed password with the plain text password, then returns true if they match, false if they do not. I have also included the wp-settings.php and wp-load.php, just trying to get my php file to work for my validation.

I am creating this so that users will not be taken away from my login in lightbox if they type in a wrong username or password.

This is my jQuery function to check the password:

jQuery.post("/wp-content/themes/Landing/includes/check_password.php", {password:pWd2, email:email},
            function(data){
                if( data == '1' )
                {
                    CheckPassword = true;
                }else{
                    //show that the password is NOT available
                    alert("The password and/or username you have entered is incorrect!");
                    CheckPassword = false;
                }  
            });

UPDATE!!!::

Ok, I got my php file working like it should, and my jQuery.post is working as it should. I am having a logic error now, however. I am using chrome tools and stepping through the code, I need to return false to the form to keep the webpage from refreshing/redirecting. It seems to step through the function(data) after submitting for the check I have in place here:

if (CheckUsername == false){
        return false;
    }
    if (CheckPassword == false){
        return false;
    }
    else{
        return true;
    }

it checks ^ ^ that block of code before stepping into the post function and setting CheckPassword to false if password is incorrect.

Jacob Boyd
  • 672
  • 3
  • 19
  • what do you get if you put '/wp-content/themes/Landing/includes/check_password.php in your browser? any php errors (Make sure error reporting is on) – atmd Jan 14 '15 at 14:03
  • I get a blank white page – Jacob Boyd Jan 14 '15 at 14:11
  • my check_username.php gives me a 0 – Jacob Boyd Jan 14 '15 at 14:12
  • Id expect an error if there was something wrong, so if error logging is on then maybe not, if you put echo "here"; on the line above "$connection = " etc do you see it when you manually go to the page? – atmd Jan 14 '15 at 14:18
  • I see the echo statement, I did have to change my includes statements they were breaking the page. However, after fixing those, deleted the 'echo "here";' and retesting, I still am not getting the desired results. – Jacob Boyd Jan 14 '15 at 14:52

1 Answers1

0

This line is supposed to establish a connection to your database:

$connection = mysqli_connect("databaseAddress", "login", "password", "table"); //creates a database connection

"DatabaseAddress" isn't a valid database address, and the other options probably aren't either. You have to fill out those credentials. When using Wordpress, some constants are defined in wp-config.php. Try this line:

$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD); //creates a database connection
rdiz
  • 6,136
  • 1
  • 29
  • 41
  • Sorry, I do know that, I changed that information so I wouldn't be giving out the database creds to everyone :) my fault I should have made that clear – Jacob Boyd Jan 14 '15 at 14:09
  • Aha, that makes sense. I will delete this answer in 15 minutes, please make sure that you correct your post, or someone else will notice that as well ;) – rdiz Jan 14 '15 at 14:10