Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc html.password set value

Tags:

asp.net-mvc

I've got a html.password helper control on an edit profile type screen. Is there a way to set the value of this when the page first loads so that if the user doesn't want to change their password, the existing one gets passed back to the controller.

Thanks Nick

like image 538
Nick Swan Avatar asked Nov 23 '25 21:11

Nick Swan


2 Answers

Html.Password helper does not use ViewData automatically (see ASP.NET MVC source, InputExtensions.cs file, line 78, line 184). You need something like this:

<%= Html.Password("password", ViewData["password"]) %>

UPDATED:

Tested in Opera 10b, Firefox 3.5, Internet Explorer 8

like image 140
eu-ge-ne Avatar answered Nov 25 '25 10:11

eu-ge-ne


I know this isn't a direct answer to your question, but coming at this from the user's point of view, would the user want their password being transmitted like this. I know I would not want any of my passwords transmitted anywhere unless it was absolutely necessary.

Most sites that I've seen only require a new password in the profile screen if it needs to be changed. If it is to remain the same and not updated the blank password fields are an indication of that. It also means that you can store the passwords in a more secure way (e.g. a one way salted hash) that does not permit password retrieval in any way (which if they could be retrieved would be a potential security risk in itself)

like image 25
Colin Mackay Avatar answered Nov 25 '25 11:11

Colin Mackay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!