2

First off, I apologize if there is a duplicate of this roaming around somewhere...I have spent the better part of the past hour looking for the solution, with no luck, but maybe I just suck at picking keywords.

Currently working on a frontend profile environment for a client, and one of the options that is being provided is the ability to set and change a password.

One of the things that I cannot seem to find a solid answer for, is whether or not I need to do any security measures for that user-input password, or if the wp_update_user() function has it built in?

I originally thought that I needed to use wp_hash_password on the string that is passed to wp_update_user's user_pass...but that's not working, of course, because it's storing the hashed version as the password into user_pass, and then whatever the user had input becomes useless :P

So...any security tips on how I can "properly" allow users to set and update their passwords from the frontend, without using anything related to the default wordpress dashboard?

Thanks in advance for any help that anyone can provide.

Quick preview of the code for the password portion of the dashboard:

Portion of the php file that takes the user-input password and stores it

I take the password from the form, via AJAX, grab it with $_POST, and then attempt to place it into the database...just making sure whether or not it is this simple, or if there are security measures I need to consider?

$user_data = array(
    'ID'=>$user->ID,
    'user_pass'=>$password
);
wp_update_user($user_data);

form input on the frontend

<input type='password' name='new_password' placeholder='What would you like your password to be?' id='[xxxx-hidden-for-project-anonymity]' style='text-align: center; text-indent: 0;'/>

UPDATE - More specific details, step-by-step planned password input

  1. User is asked to set their password, after having verified their email address.
  2. They put that password into a text input.
  3. On form submit (the password input is the only input in this particular form), I have AJAX in place to take the password from the input to a php function that is connected to WordPress.
  4. After this, it needs to update their password in the database.

I have code that achieves all of the above steps. My question is security. What security measures do I need to implement while the password is taken from the form to the AJAX call, and then measures in the PHP function as it's taken from the function to the database?

1 Answer 1

2

I think you are referring to two different things..

1) Verifying the request. You should be using WP Nonces to verify the request and protect it against XSS. That should be a practice for all your forms. you could also add additional layer of security by integrating a reCAPTCHA.

2) Data Encryption when you attempt to hash the password. Which in this case, your only option is to use SSL. Using it will secure all data transfer between client and server, additionally it goes beyond this single process of updating password.

4
  • Okay -- then my original fear of having oversimplified it seems to be reality. How would you suggest I go about allowing the user to update their password, then? Code samples would be awesome, if possible, as that is how I learn. I take a piece of code that I know are reliable, and then I pick them apart to learn what each part does and then figure out how to implement it into what I have. But if that's not possible, would you be up for elaborating a bit on the above two, please? Thank you! And thank you as well for the info above that you provided.
    – Akel
    Mar 13, 2016 at 1:32
  • I think you should read the links above first then let me know if you have questions. Mar 13, 2016 at 1:40
  • True. I apologize. I should have taken a look before asking for code samples. I understand reCAPTCHA, and am using it currently during the sign up process. Will look into implemented it into the dashboards, as well whenever settings are saved. Nonces still have me confused. Not so much the "how", but the "why?" Everything I do will be via AJAX, so any questions that I have will be in reference to check_ajax_referer(). How does implementing this benefit me, and how can somebody use it against me if I were to make the mistake of not implementing it? As far as implementing them [cont...]
    – Akel
    Mar 13, 2016 at 1:55
  • is it okay to use a hidden input in the form, set with php, then grab it (using javascript) from that input as the form is submitted and pass it to AJAX, or is there anything in that process that defeats the purpose of an AJAX nonce?
    – Akel
    Mar 13, 2016 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.