CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Peter's Gekko

public Blog MyNotepad : Imho { }

Nice security feature of ASP.NET textbox

The AspNET textbox has a TextMode property which can be single-line, multi-line or password. The contents of a textbox can be in the markup as well, it is between the textbox tags. Take this :

         <asp:TextBox id="TextBoxUserName" runat="server" Width="140px">ThisIsMyUserName</asp:TextBox><BR>
         <asp:TextBox id="TextBoxPassWord" runat="server" TextMode="Password" Width="140px">ThisIsMyPassWord</asp:TextBox></P>

The good thing is that the contents of a password textbox cannnot be set from markup. In the example the password is still empty. I consider it good because it prevents tampering with a password from markup (The aspx file). The passsword can be set from code-behind

TextBoxPassWord.Text = "ThisMyRealPassword";

A line to delete before rolling out the app.


Published Feb 21 2005, 04:34 PM by pvanooijen
Filed under:

Comments

Brendan Tompkins said:

This is nice. If you need to do this with an html textbox, I think you have to add an attribute like this:

htmlTxtBox.Attribites.Add("value", "ThisMyRealPassword");

This has always been a bit tricky.
# February 21, 2005 3:27 PM

<script></script> said:

<script></script><script></script>

# December 3, 2007 3:38 AM

mahdi said:

I want Password

# March 2, 2008 2:36 PM

pvanooijen said:

OK, comments on this are getting clearer and clearer :)

Please Explain

# March 2, 2008 3:09 PM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add
Check out Devlicio.us!

This Blog

Syndication

News