Skip to content

A Windows Forms control that enables the user to enter password text, momentarily showing each character entered

License

Notifications You must be signed in to change notification settings

njonsson/PasswordTextBox-Control

Repository files navigation

PasswordTextBox Control

‘PasswordTextBox-Control’ NuGet package

See what’s changed lately by reading the project history.

It’s common knowledge that the UseSystemPasswordChar and PasswordChar properties of the System​.Windows​.Forms​.TextBox control let you obscure user input of secret information such as passwords. But you may have wanted behavior such as touch-screen devices exhibit: user input is momentarily displayed before being replaced by a password character. TextBox can’t do that.

PasswordTextBox is what you were looking for.

PasswordTextBox control animated demonstration

Features

  • Accept user input via the keyboard, the clipboard, and drag-and-drop
  • Prevent the user or system from copying control content to the clipboard if a password character is in effect
  • Show input just once before replacing it with the password character, never allowing any input to be revealed again after it has been obscured
  • Support the use of the system-defined password character
  • Support the use of a custom password character
  • Support the use of no password character at all (which makes the control behave like a standard text box)
  • Support variable delay in connection with the password character
  • Observe system settings governing text quality (i.e., antialiasing)
  • Support user input via the keyboard by momentarily displaying each typed character
  • Support user input via the clipboard by momentarily displaying pasted content
  • Support user input via drag-and-drop by momentarily displaying dropped content

Installation

Install the NuGet package. You can do this using the Visual Studio NuGet plugin, or from the command line in your project folder: nuget install PasswordTextBox-Control.

Using the Visual Studio Windows Forms Designer is optional, and configuring it requires some manual steps. Once PasswordTextBoxControl.dll is a reference of your project, you need to add the control to the Visual Studio Toolbox so it can be dropped on forms in the designer:

  1. Click Choose Toolbox Items… in the Tools menu.
  2. On the .NET Framework Components tab of the Choose Toolbox Items dialog box, click the Browse… button.
  3. Navigate to the packages folder of your project, and within that find the PasswordTextBoxControl.dll version that corresponds to the .NET Framework version you’re using.
  4. Click OK to save the changes to the toolbox.
  5. Look for PasswordTextBox among Common Controls in the toolbox.

Usage

See the PasswordTextBox.Test.Gui project in this solution for a demonstration of the behavior of the control. Salient properties include:

UseSystemPasswordChar property

If true, this property makes user input appear as bullet characters after it momentarily appears normally. If false, then PasswordChar takes effect.

This property defaults to true.

PasswordChar property

This property makes user input appear as a specific character after it momentarily appears normally. The value of this property has no effect unless UseSystemPasswordChar is false.

This property defaults to '\0' (the null character), which makes the control behave like a standard text box if UseSystemPasswordChar is false.

PasswordCharDelay property

This property controls the time in milliseconds during which user input appears normally before appearing as the password character.

This property defaults to 1000 (i.e., one second).

Text property

As you might expect, this property stores user input regardless of any password character that may be in effect.

Contributing

To submit a patch to the project:

  1. Fork the official repository.
  2. Create your feature branch: git checkout -b my-new-feature.
  3. Commit your changes: git commit -am 'Add some feature'.
  4. Push to the branch: git push origin my-new-feature.
  5. Make sure all tests in the project are still passing, and add test coverage of new behavior as appropriate.
  6. Create a new pull request.

To release a new version:

  1. Update the project history in History.md, and commit.
  2. Update the version numbers in the PasswordTextBox-Control.nuspec file and in all AssemblyInfo.cs files, and commit.
  3. Build the NuGet package: nuget pack PasswordTextBox-Control.nuspec.
  4. Publish the NuGet package: nuget push PasswordTextBox-Control.X.Y.Z.nupkg where X.Y.Z is the version you just built.
  5. Tag the commit and push commits and tags.

License

Released under the MIT License.

About

A Windows Forms control that enables the user to enter password text, momentarily showing each character entered

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages