Why is password field updated when updating other fields?
Why is password field updated when updating other fields?
ekkodill
Posts: 2Questions: 1Answers: 0
In my datatables editor table with users i cant update any field without password changing each time. I guess it's because setFormatter function returns password_hash ( $val, 1) each time. But how do i fix this, so i can:
1. Update fields without password changing.
2. Keep password hash somehow so new or updated passwords will be hashed.
Field::inst( 'user.password' )
->validator( 'Validate::notEmpty' )
->setFormatter(function ( $val ) {
return password_hash( $val, 1);
}),
"fields": [
{
"label": "Passord",
"name": "user.password",
"type": "password"
},
]
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I think the quickest solution is to use the
preSubmit
event and check if the password value has been set. If not, just delete it and the server-side scripts will not attempt to set it:A better solution would probably be to use the
set()
method of the PHP libraries and setting that tofalse
if the field is empty. However, that would really need theset()
method to accept a closure function so you could compute if you want to set it or not - it currently doesn't have that ability.An even better solution will be in v1.5 :-). I'm going to add an option so that only values which have changed will be submitted. In this case the password will not have changed (presumably you have a getFormatter making it an empty string so they can't read the password hash!) so it wouldn't be submitted automatically.
Allan
Thank you for taking time answering:)
I didnt really get it to work, but i figured i would just remove the whole password field for now.
Thank you anyways.
Hi, I have been testing what you have written and not work for me, Can you give an example?
thanks!
The above will not work in 1.5 due to a change in the client / server comms.
I would suggest trying the
submit
options that are present in 1.5.Or better yet would be to never read the password from the database and only write when a value is submitted. That can be done with server-side events.
Allan
ok, it works! But you can do to it is done without the click event.To operate with the buttons above http://prntscr.com/8m3a2d
I have :
up!
I'm not sure why this was bumped - you noted in your previous message that it works for you now. Could you clarify what your question is for me please?
Allan
ok, the problem is that now edits the onclick event when I click the row.
I want to edit when I press the Edit button(Modificar) http://i.imgur.com/yqanLsK.png
greetings and thanks!
I'm afraid I would need a link to the page to understand what is going wrong here. Without being able to see the code I don't know why it would immediately enter editing mode on click in the row, unless you have a click event handlers that it triggering that action.
Allan
ok! I you send the information for message.
thanks!
Thanks for the information. In your code (
script.js
) you have:That is why it is triggered an edit whenever you click a row - it is being told to :-). If you don't what that, remove that code.
Allan
Yes, but now if I modify a field, it changes the password, though I do not change it.
I want that when I edit with the button to edit, the password does not change if I do not change it.
With this it works but only when I click in the row and not in the button to edit(MODIFICAR) http://i.imgur.com/yqanLsK.png .
Thank you and sorry for the inconvenience!
I recently wrote a blog post about how to handle the submission of password fields.
Also, I think I understand why you added that event handler code now - you only want the changed fields to be submitted? If so, then use the
formOptions.main
object to set thesubmit
option tochanged
(it is defaultall
).Allan
Already work!. Thank you very much, a greeting! :-):-):-):-)
The code in PHP Server