skip to Main Content

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

2

Answers


  1. 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 );
      },
    });
    
    Login or Signup to reply.
  2. WordPress generates passwords by function wp_generate_password()documentation

    At the end of the function there is hook random_password, so if you wnat to use your custom code to generate a password instead of native WP function, you need to add filter and in function you can write your custom code for generating password. This function will be called always at the end of wp_generate_password().

    function custom_random_password( $password ) {
      // here you make your password generation
      $password = 'your-password';
      return $password; 
    }
    add_filter( 'random_password', 'custom_random_password' );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search