-
-
Save salcode/e33c8c7f241e7c28cd3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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