• Resolved adamharms

    (@adamharms)


    In inc/core.php there is the action hook wpmem_pwd_change . Is it possible for you to add another action hook called something like wpmem_pre_pwd_change before the password is set, right above error checking?

    Something like this?

    
    159 | if ( isset( $_POST['formsubmit'] ) ) {
    160 |
    161 | $is_error = false;
    162 |
    163 | $pass1 = wpmem_get( 'pass1', false ); //trim( $_POST['pass1'] );
    164 | $pass2 = wpmem_get( 'pass2', false ); //trim( $_POST['pass2'] );
    165 |
    166 | do_action( 'wpmem_pre_pwd_change', $user_ID, $pass1, $pass2 );
    167 |
    168 | // Check for both fields being empty.
    169 | $is_error = ( ! $pass1 && ! $pass2 ) ? "pwdchangempty" : $is_error;
    

    The reason for this is that I’d like to be able to force the user to enter their current password and validate it before changing to their new password.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Chad Butler

    (@cbutlerjr)

    There’s already a filter that will do that – wpmem_pwd_change_error. This filter allows for custom validation. Just make sure that if $is_error already has a value, that regardless of your custom validation that you return the $is_error value.

    Thread Starter adamharms

    (@adamharms)

    Ah! Awesome! I don’t know how I missed that, sorry. Thanks for the awesome plugin and great support. All of these hooks and filters are a life saver.

    Thread Starter adamharms

    (@adamharms)

    Sorry to open this up again but I’m hoping you can help me with this filter. I’m going insane trying to figure out why it isn’t working. Here is my code –

    add_filter('wpmem_pwd_change_error', 'wp_members_validate_old_pass', 10, 3);
    
    function wp_members_validate_old_pass($is_error, $user_ID, $pass1) {
    
      if ( $is_error ) {
    
          // There is already an error 
          return $is_error;
        
      } else {
    
        $current_password_input = wpmem_get('currentpass', false);
        $user = get_user_by( 'ID', $user_ID );
        $hashed_old_pass = $user->data->user_pass;
    
        if (wp_check_password( $current_password_input, $hashed_old_pass, $user_ID )) {
    
          // Entered current password DOES match
            $is_error = false;
    
            return $is_error;
    
        } else {
    
            // Entered current password DOESN'T match actual current password
    
            $is_error = "pwchangerr";
    
            return $is_error;
    
        } 
      }
    
    };

    Everything seems to be working and the value “pwchangerr” is being returned with the filter to the $is_error variable. I checked by temporarily editing the inc/core.php file to log the variable when $is_error is confirmed to have a value after the filter.

    But nothing happens when the function returns “pwchangerr” or any other value, the page just refreshes. “pwchangerr” is the same value that is returned by the plugin when the passwords don’t match. What am I doing wrong?

    Thread Starter adamharms

    (@adamharms)

    I found this post on the wp member site and went ahead and purchased a year membership to access it – http://rocketgeek.com/tips-and-tricks/add-current-password-confirmation-to-change-password-form/ . I’ll send a message to premium support if I am having any more problems, thanks!

    Plugin Author Chad Butler

    (@cbutlerjr)

    Thanks for signing up and glad to have you as a premium support subscriber.

    Just for anyone who comes along later, the tutorial and set of code snippets at the support site linked above describes how to implement this process. So we were able to get a fully working version of confirming password in place.

    The primary issues with the code in this thread were that (1) it did have a typo in it (“pwchangerr” should have been “pwdchangerr”) and (2) it needed to also trigger a message for the user.

    Incidentally, for those not inclined to use custom code snippets, I am working adding this process as a feature in either the Advanced Options extension or a new Security extension that is being worked on (it will replace the http://rocketgeek.com/plugins/wp-members/extensions/registration-blacklist-extension/ extension – essentially adding more security oriented features such as enforcing strong passwords, password expiration, disallowing concurrent logins, etc). These extensions are available to support subscribers.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Request: Action Hook before password change in inc/core.php’ is closed to new replies.