Skip to content

Instantly share code, notes, and snippets.

@vishalbasnet23
Created September 21, 2015 08:22
Show Gist options
  • Save vishalbasnet23/8bf6f11efd9df3096fa4 to your computer and use it in GitHub Desktop.
Save vishalbasnet23/8bf6f11efd9df3096fa4 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