I have a wordpress plugin, I need to let users register without warning them that some "passwords" are not allowed. In my foreach loop, I need to check 1 password if it was used, if it was not, I will authenticate the user.
This is my current code, first loop, it will check user credentials, if they were incorrect, it will show erorr message, if correct, it will direct him to his CP:
if (isset($_POST["username"])) {
$creds = array();
$creds['user_login'] = $_POST["username"];
$creds['user_password'] = $user_pass;
if (isset($_POST["remember"]))
$creds['remember'] = true;
else
{
$user = wp_signon($creds, false);
if (is_wp_error($user))
echo $user->get_error_message();
else
wp_redirect(admin_url());
}
}
But what I need is that to check user credentials first if they were correct, I need to direct him to his CP, if not correct, I need to pass the current loop to next check,because I need to add my if statement to check user in each loop if he was using a certain words of passwords like "passw0rd". any advise?
$user = wp_signon($creds, false);
if (is_wp_error($user))
echo $user->get_error_message();
else
wp_redirect(admin_url());
This is the part of the code which you should be interested in utalizing. As you state in your question, you want to do something after the user has failed to login.
If you edit that to something like:
function nextCheck($userData){
echo $userData['user_login'].' '.$userData['user_password'];
}
$user = wp_signon($creds, false);
if (is_wp_error($user)){
nextCheck($creds);
echo $user->get_error_message();
}
else
wp_redirect(admin_url());
You'll be able to carry on with what ever your next task is.