Check username/password on wordpress

I am trying to figure how I can check a user’s password which is stored on a sql database on wordpress. I’ve been searching for this all day, but the solution seems very simple, however I can’t get it to work.

Running this code returns a blank page, so I don’t know what’s going on.
Also entering a wrong user/password, doesn’t display an error message.

Read More

It seems I have to use wp_signon() as explained here:

But when I run this code on a php file on my bluehost server, the same one that hosts the wordpress site, it doesn’t work.

<?php

custom_login("joe","joepass");

function custom_login($username, $password) {

$creds = array();
$creds['user_login'] = $username;
$creds['user_password'] = $password;
$creds['remember'] = true;

$user = wp_signon( $creds, false );

if ( is_wp_error($user) )
    echo $user->get_error_message();
}


// run it before the headers and cookies are sent
add_action( 'after_setup_theme', 'custom_login' );


?>

What am I missing here? It’s probably something very basic, but I’m completely clueless as to what to do.

My server hosts two websites. So don’t I need to specify which database and table it needs to use to validate the user/pass?

If I put an echo statement after ‘$user = wp_signon( $creds, false );’, it doesn’t get printed. Why is that? Shouldn’t it print the statement, wp_signon returns a $user?

Sorry if the answer is simple and if it has been asked before, could you please point me a solution.

Thanks.

Related posts

1 comment

  1. The reason you’re getting a blank page is because you’re triggering a fatal error in PHP.

    You’ve created a function called custom_login() which has two required parameters, username and password. Then you hook that function into the after_setup_theme action.

    add_action( 'after_setup_theme', 'custom_login' );
    

    This hook isn’t going to pass in any arguments to custom login and since it requires two that’s the source of your problem.

Comments are closed.