0

User registrations are working great, except that the password that he chose isn't being accepted when the user tries to sign in, generating a new password from the back-end and trying to login with the generated password works. what am i missing here?

$email = $_POST["email"];
$password = $_POST["password1"];
$firstName = $_POST["fname"];
$lastName = $_POST["lname"];
$company = $_POST["company"];
$website = $_POST["website"];
$address = $_POST["address"];
$street = $_POST["street"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$country = $_POST["country"];
$home = $_POST["home"];
$office = $_POST["office"];
$mobile = $_POST["mobile"];


if( null == username_exists( $email ) ) {

  $user_id = wp_create_user( $email, $password, $email );

  wp_update_user(
    array(
      'ID'          =>    $user_id,
      'nickname'    =>    $email_address,
      'first_name'  =>    $firstName,
      'last_name'   =>    $lastName,
      'user_url'    =>    $website
    )
  );

  update_user_meta( $user_id, 'company', $company );
  update_user_meta( $user_id, 'address', $address );
  update_user_meta( $user_id, 'street', $street );
  update_user_meta( $user_id, 'city', $city );
  update_user_meta( $user_id, 'province', $state );
  update_user_meta( $user_id, 'postalcode', $zip);
  update_user_meta( $user_id, 'country', $country );
  update_user_meta( $user_id, 'home', $home );
  update_user_meta( $user_id, 'office', $office );
  update_user_meta( $user_id, 'mobile', $mobile );

  $user = new WP_User( $user_id );

  $user->set_role( 'subscriber' );

} else {
    echo 'user exists';
}

replacing $password in wp_create_user() with 'testpassword' or adding a new line to the wp_update_user() array 'user_pass' => 'testpassword' both didn't work.

2
  • What happens when you try something simple like wp_create_user( 'testuser', '[email protected]', 'test' ); does it work or not? Commented Sep 25, 2016 at 20:56
  • @AhmedMahdi nop, a user was created with a username : testuser and the email wasn't saved, and trying to login with both [email protected] and test failed Commented Sep 25, 2016 at 21:03

2 Answers 2

0

Dont pass plain text as password, use this function:

wp_set_password( $password, $user_id );

Keep in mind that it should only be run on user creation (so just once), otherwise the password might keep changing.

1
  • Thank you for your answer.. but it didn't work either, i found the solution and i'll post it as an answer Commented Sep 26, 2016 at 11:36
0

For whoever passes by and has the same problem:

For me, i was using "New User Approve" Plugin that, after deep searching inside the plugin code, generates a new random password and hashes it then overrides whatever password was set when the admin approves that new user. 2 solutions are possible:

  1. edit the plugin code
  2. find other plugin or add some functions to your functions.php that adds Admin Approval to your new users

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.