Click here to Skip to main content
12,828,983 members (41,520 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » Howto » Downloads


34 bookmarked
Posted 24 May 2007

How-to safely keep a password field during postbacks and why it shouldn't be done

, 31 May 2007
Think of this article as a beginner's guide to think about design and security when solving problems.
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="KeepPassword.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <title>Keep it safe!</title>
    <form id="form1" runat="server">
        <asp:Label ID="lblUser" runat="server" Text="User"></asp:Label>
        <asp:TextBox ID="txtUser" runat="server"></asp:TextBox>
        <asp:Label ID="lblTypedUser" runat="server"></asp:Label><br />
        <asp:Label ID="lblPassword" runat="server" Text="Password"></asp:Label>
        <asp:TextBox ID="txtPassword" runat="server" MaxLength="128" TextMode="Password"></asp:TextBox>&nbsp;
        <asp:Label ID="lblTypedPassword" runat="server"></asp:Label>
        <br />
        <asp:Button ID="btnPostBack" runat="server" OnClick="btnPostBack_Click" Text="Post the page back!" />
        <br />
        <br />
        <asp:TextBox ID="txtPageInstructions" runat="server" BorderStyle="None" Rows="11"
            TextMode="MultiLine" Width="100%">1. Enter the page and type &quot;user1&quot; as a user and &quot;1&quot; as the password.
2. Click &quot;Post the page back!&quot;. Verify that the user and password are maitained. Note that a bunch of '*' is presented in the password field.
3. Click &quot;Post the page back!&quot; again and verify that the password remains untouched. 
4. Enter &quot;2&quot; as the password and click &quot;Post the page back!&quot;. Note that the password is erased when you click on the password field.
5. Click &quot;Post the page back!&quot; and verify that the password changed to &quot;2&quot;. 
6. Click on &quot;view page source&quot; on your browser. Verify that the password is *not* presented in the page source, so security is preserved.
7. Try anything else and report your findings!</asp:TextBox></div>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Roberto Colnaghi
Software Developer
United States United States
I'm a passionate developer and videogame player.
Been in touch with Objective-C, Javascript, C#, C, Guild Wars 2, Tera and many more.

Javascript is one of my favorite languages.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170326.1 | Last Updated 31 May 2007
Article Copyright 2007 by Roberto Colnaghi
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid