Home > Back-end >  How to create Forgot password user endpoint API in WordPress?
How to create Forgot password user endpoint API in WordPress?

Time:11-23

How can we use custom code to generate a password for the forgot password user endpoint API?

CodePudding user response:

I used this plugin: bdvs password reset

You can simply reset password and set new password. I put example some code:

Reset Password:

$.ajax({
  url: '/wp-json/bdpwr/v1/reset-password',
  method: 'POST',
  data: {
    email: '[email protected]',
  },
  success: function( response ) {
    console.log( response );
  },
  error: function( response ) {
    console.log( response );
  },
});

Set New Password:

$.ajax({
  url: '/wp-json/bdpwr/v1/set-password',
  method: 'POST',
  data: {
    email: '[email protected]',
    code: '1234',
    password: 'Pa$$word1',
  },
  success: function( response ) {
    console.log( response );
  },
  error: function( response ) {
    console.log( response );
  },
});

CodePudding user response:

function custom_random_password( $password) {
  // here you make your password generation
  $password = 'your-password';
  return $password; 
}
add_filter( 'random_password', 'custom_random_password' );
  • Related