Skip to content

Instantly share code, notes, and snippets.

@alokstha1
Created July 7, 2016 16:05
Show Gist options
  • Save alokstha1/0251b0db193227c241707938f2f35340 to your computer and use it in GitHub Desktop.
Save alokstha1/0251b0db193227c241707938f2f35340 to your computer and use it in GitHub Desktop.
Change password frontend WP function
function change_pass_frontend() {
require_once( ABSPATH . 'wp-includes/class-phpass.php');
$old_pass = $_POST['old_pass'];
$new_pass = $_POST['new_pass'];
$user_id = $_POST['user_id'];
$user_data = get_userdata( $user_id );
$wp_hasher = new PasswordHash(8, TRUE);
$password_hashed = $user_data->user_pass;
if($wp_hasher->CheckPassword($old_pass, $password_hashed)) {
wp_set_password( $new_pass, $user_id );
die('Your password is changed succssfully');
} else {
die('Your old password did not match');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment