Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryManaging Website Forms

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Show/Obfuscate Password Field

The content within a password field generally is obfuscated. As a person types or taps their password into the field, or pastes it in, the characters are presented only as asterisks.

Generally, a secure password is over 13 characters in length and composed of a mix of upper-case, lower-case, numbers, and symbols.

When a person types that in and momentarily loses their place or is uncertain which character was typed last, the asterisks make it impossible to edit with certainty.

One way to do it is to type the password in a text editor, then copy it and paste it into the password field.

For your own forms, the password field can have an option. Let the person specify whether or not the password is obfuscated within the field.

It starts out obfuscated.

If the person loses their place, they can tap the "show" link. Then tap "obfuscate" when they have their place.

JavaScript is used to switch between obfuscated and plain text.

Here is a working example.

Password. (show)

Tapping on the "show" link changes the field to type="text". Tapping on the "obfuscate" link changes the field to type="password".

The Form Field and Show/Obfuscate Links

The form in the above example is coded like this.

Password. 
<span id="makeplaininput" style="display:inline;"><a href="javascript:ShowPasswordCharacters()">(show)</a></span>
<span id="makepwinput" style="display:none;"><a href="javascript:ObfuscatePasswordCharacters()">(obfuscate)</a></span>
<br>
<input id="pwinput" type="password">

The "show" and "obfuscate" links are in span tags with id values. The JavaScript will use the id values to display and un-display the links.

The "show" link is id makeplaininput. It's coded with display:inline; so it's displayed when the page first loads. Clicking on the link runs the JavaScript ShowPasswordCharacters() function.

The "obfuscate" link is id makepwinput. It's coded with display:none; so it's un-displayed when the page first loads. When it's displayed and the link is clicked, the JavaScript ObfuscatePasswordCharacters() function runs.

The password field itself is id pwinput. When ShowPasswordCharacters() or ObfuscatePasswordCharacters() runs, it changes the password field into type="text" and type="password", respectively.

The JavaScript

The JavaScript is below.

The id values and function names of the JavaScript are color coded to match the color of the form code, above.

<script>
function ShowPasswordCharacters()
{
    document.getElementById("makepwinput").style.display = "inline";
    document.getElementById("makeplaininput").style.display = "none";
    document.getElementById("pwinput").type = "text";
}
function ObfuscatePasswordCharacters()
{
    document.getElementById("makepwinput").style.display = "none";
    document.getElementById("makeplaininput").style.display = "inline";
    document.getElementById("pwinput").type = "password";
}
</script>

When the "show" link is clicked, ShowPasswordCharacters() runs and

  1. the "show" link is un-displayed,
  2. the "obfuscate" link is displayed, and
  3. the input field is made into type="text".

When the "obfuscate" link is clicked, ObfuscatePasswordCharacters() runs and

  1. the "show" link is displayed,
  2. the "obfuscate" link is un-displayed, and
  3. the input field is made into type="password".

Place the JavaScript anywhere on the web page. It may be imported from an external file. The JavaScript needs no customization.

The show/obfuscate option can make the form more user-friendly and accessible.

(This article first appeared in Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC