views:

68

answers:

4

I want to edit an user. I dispay the corresponding data(username, email,..etc..password, confirmation pass) The problem is that those password fields are empty.

  1. Q: When i display data in the form the two password fields are empty. How can i make them contain data? Thanks.

I am using asp.net-mvc 2

                    <div class="editor-label">
                        <%: Html.LabelFor(m => m.Password) %>
                    </div>
                    <div class="editor-field">
                        <%: Html.PasswordFor(m => m.Password)%>
                        <%: Html.ValidationMessageFor(m => m.Password)%>
                    </div>
A: 

Could not really understand the question, but I am assuming you are talking about when a user tries to edit their account information:

Just make it so that if they are logged in, and they do not have any values in the password fields, then the password does not get updated.

There are certainly security risks to sending the password to the client.

Martin
I rephrased, sorry for ambiguous question. I don't send the pass to the client. I am sending 0123456789.
gigi
A: 

You do not have a view problem. I think your problem comes from the model. If you are editing a user, do not send the password to them. In your model class/repository, just update the necessary fields if no new password is coming from the view, else update everything.

I think you are trying to pack too much functionality in 1 post. If you want to change password, you have a different controller for that.

Your Answer

If you are sending back the password to the user in plain text. Might as well put it in a plain TextBox. That way, it will be persisted on the view.

Or

Use plain Html:

<input type="password" id="Password" value="<%: m.Password" />
Shawn Mclean
The Model is Username="gigi" Email="[email protected]" Password="0123456789" and ConfirmationPassword="0123456789" but in the view the password fields are empty
gigi
So, a password field from the view cannot be filled with data from the model?
gigi
nope, not with the asp.net mvc helpers.
Shawn Mclean
A: 

Just set it so that if no password is entered, the password does not get changed.

You'll probably have to remove the [Required] attribute from the Password and ConfirmPassword properties in the model your view is using in order to accomplish this.

The model would usually be a class in Models/AccountModels.cs

mootinator
A: 

If you set the textmode of an <input> to password you cannot write to it. Password text boxes are read only.

If you see a password prepopulated, it's because the browser remembered it.

Jack Marchetti