I have a database with user information from a another project. Now I want to link this user data with my new wordpress installation. I want, if a user is about to login and has no WordPress profile yet, but a profile is in that other database already, then wordpress needs to create a profile based on the data, that already exists in the other database.
I’m already done with the login and it works fine…
add_filter('authenticate', 'check_login', 40, 3);
function check_login($user, $username, $password) {
$user = get_user_by( 'login', $username );
$hash = kbHash($password);
if ( $user ) {
if (!wp_check_password( $hash, $user->data->user_pass, $user->ID) ) {
$user = NULL;
}
} elseif ($kbCredentials = isKanuboxUser($username)) {
if ($kbCredentials['hash'] == $hash)) {
$user_id = wp_create_user( $kbCredentials['username'], $kbCredentials['hash'], $kbCredentials['mail'] );
$user = get_userdata( $user_id );
} else {
$user = NULL;
}
} else {
$user = NULL;
}
return $user;
}
function kbHash($password) {
//TODO: additional hashing from other project
$hash = $password;
return $hash;
}
Now, the problem is, if some user edits his password, I need to do this hashing too and update it in the original database. Are there appropriate hooks inside wordpress?
I only found this: add_action( 'profile_update', 'some_function' );
But in that function I am not able to add my hashing to the plain text password before the wp-hashing is applied.
How to solve this?