The previous answer, while actually partially true, contains some wrong assumptions and uses plain old SHA1, which is actually discouraged now in 2022, and since my edits were rejected as too substantial and the question doesn't have a proper answer yet, I'll write my own answer.
You can use patch
semantics for exactly what you're trying to do - you don't need to provide a fully-populated User
object for that, just the fields you actually change - in your case, only the new password details, omitting any user fields you aren't changing in the process.
For instance, this would be the correct payload if you want to change a password to Testpassw0rd1
(assuming your app will use a salt string of Usesomesalthere1
and SHA-256 based password hashing, which is considered a safe algorithm):
{
"password": "$5$Usesomesalthere1$F8UxCaJUKHYgoZUY01YRiogSXXRquSmFuTHcpFOVrD7",
"hashFunction": "crypt"
}
(Yes, that's the entire payload you'd want to send to the patch
method endpoint for your desired user.)
A proper password
value for any string you want you can obtain from libc crypt()
function, using $5$your_salt_value$
as the second parameter (replace your_salt_value
with whatever you use in your app - you just need to have it consistent with the value used in password
JSON parameter, can't have it different in both places or the resulting password won't work at all).