How to make password field not reset?
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.
- 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">
开发者_如何学C <%: Html.PasswordFor(m => m.Password)%>
<%: Html.ValidationMessageFor(m => m.Password)%>
</div>
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.
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.
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" />
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
精彩评论