Skip to content

Instantly share code, notes, and snippets.

@salcode
Last active November 18, 2020 16:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save salcode/e33c8c7f241e7c28cd3f to your computer and use it in GitHub Desktop.
Save salcode/e33c8c7f241e7c28cd3f to your computer and use it in GitHub Desktop.
<?php
add_filter( 'check_password', 'fe_magento_check_password', 10, 4 );
function fe_magento_check_password( $check, $password, $hash, $user_id ) {
if ( $check ) {
// the password is already accepted
// do nothing further
return $check;
}
// get user Magento password
$magento_pwd_parts = explode(
':',
get_user_meta( $user_id, 'fe_magento_pwd', true )
);
if (
! $magento_pwd_parts // the string exploded was empty
|| ! is_array( $magento_pwd_parts ) // result is not an array
|| ! sizeof( $magento_pwd_parts ) // the results are an empty array
) {
// exit early if we were unable to retrieve a Magento hashed password
// from User Meta
return $check;
}
$hash = $magento_pwd_parts['0'];
$salt = $magento_pwd_parts['1'];
if ( $hash === hash( 'sha256', $salt.$password ) ) {
// success, allow the user to log in
// update WordPress to use this password
wp_set_password( $password, $user_id );
// delete Magento password User Meta
delete_user_meta( $user_id, 'fe_magento_pwd' );
return true;
}
return $check;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment