Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Create user hashing the password according to WP rules#426

Open
jgrossi wants to merge 4 commits into2.7from
create-user
Open

Create user hashing the password according to WP rules#426
jgrossi wants to merge 4 commits into2.7from
create-user

Conversation

@jgrossi
Copy link
Member

@jgrossi jgrossi commented Nov 15, 2018

This PR is related to #413

WP uses a different password hashing algorithm than Laravel does. This PR adds a UserObserver class to fill required fields and a User@setUserPassAttribute() method to hash the password according to WP rules.

Now you can create users on the fly. The required params are user_login, user_pass and user_email. Others are filled by default and the password is hashed by default.

⚠️ WARNING: this PR changes the default hashing for user creation. Since then, every created user is gonna have the password hashed by the PasswordService class.

TODO

  • Add meta fields when creating the user.

@crispy-computing-machine

This works great!

Just a note on your warning above that may confuse people:

You can still keep the Laravel Auth and WP Auth separate (even have separate register/login forms for each). Just differentiate them via namespacing:
use App\Models\User as LaravelUser;
use Corcel\Model\User as WPUser;

Register form for WP is for authors/moderators etc
Register form for Laravel is for admins etc

Can we get this merged 👍

@jgrossi
Copy link
Member Author

jgrossi commented Nov 27, 2018

@brittainmedia sounds good then! actually, I still have to add some meta fields when the user is created. WP adds some meta for each user, with roles, etc. I still have to implement that. if you want to, you're welcome!

these are the fields I said:

image

@crispy-computing-machine

In all honesty I am not sure how to achieve adding meta when creating a new user.

Would this not be down to whomever creates the user to save the meta?

$user = new User;
$user->user_login = 'testlogin';
$user->user_pass = 'testpassword';
$user->user_email = 'testemail';
$user->save();

$user->saveMeta('wp_capabilities', serialize(['administrator' => true]));

@jgrossi
Copy link
Member Author

jgrossi commented Nov 27, 2018

@brittainmedia yep, that's the point, using saveMeta(). we only have to figure out how to reproduce the correct values, and the logic behind them. not something complicated 😎

@crispy-computing-machine

Okay...

There doesn't seem to be an easy way to give explicit examples for what each meta value should be.

Most of the meta fields have filters associated with the values.
Exceptions are:
'ID', 'rich_editing', 'syntax_highlighting', 'comment_shortcuts', 'admin_color', 'use_ssl', 'user_registered', and 'role'.

Additionally the options available for each are dynamic and based on various other database values within wp_options.

See: https://github.com/WordPress/wordpress-develop/blob/master/src/wp-includes/user.php#L1446

@jakesylvestre
Copy link

+1 here, doing this by hand

@masihgh
Copy link

masihgh commented Nov 5, 2025

how can i set woocomerce details and also user first_name and last_name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants