Skip to main content

A flexible and easy to use, terminal based password input utility

Project description

GPass

GPass is a flexible and easy to use, terminal based password input utility

It is a variation of the stdiomask utility which allows users to securely input passwords onto the terminal.

However, many a times, piping, storing and redirection of the output often leads to the program not allowing the developer to safely input the password. This program was created to avert the same, along with create more types of possible masks for the passwords.

Installation

A PyPI installation can be achieved by

python3 -m pip install gpass 

A build from source can be done by

git clone https://gitlab.com/loggerheads-with-binary/gpass
cd gpass
python3 -m pip install -r requirements.txt 
python3 setup.py install

Using in your scripts

>>> import gpass

#Check below for meanings of colored and mask 
>>> var = gpass.getpass("Enter your password: " , colored = True , mask = gpass.SPECIAL_MASKS.MIMI_REVERSE)
Enter your password: ************
>>>var
'password1234' 

Masks

The following different masks can be used

  1. str : Any python string can be used as a mask

String Mask

  1. gpass.SPECIAL_MASKS.NO_MASK : Equivalent of having no mask, all characters are displayed directly. Can also be used with mask=False

No Mask

  1. gpass.SPECIAL_MASKS.BLIND_MASK : Does not echo any character. Equivalent of read -n on unix. Can also be used with mask=None or mask=''

Blind Mask

  1. gpass.SPECIAL_MASKS.DEFAULT_MASK : Uses the '*' character to mask every single input character. Can also be achieved by using '*' as the mask. Can also be used with mask=True

  2. gpass.SPECIAL_MASKS.ONE_REVERSE : Displays the last character of the input password in plaintext, and the rest of them in '*' characters, similar to some website password inputs.

  3. gpass.SPECIAL_MASKS.MIMI_REVERSE : Similar to ONE_REVERSE but also works backwards, i.e when characters are removed from the terminal.

One Reverse and Mimi Reverse

Colored Input

You can receive color input by using colored=True in the gpass.getpass function. Colors for prompt and input are also customizable with the colorset parameter, which can be a two-member list/tuple consisting of (prompt, input) colors.

Colored and Colorset

By default, the colorset = ('yellow' , 'green')
However, note that the colors must be defined. For example, magenta+cyan color does not exist and will raise a KeyError. The colors are as per those defined in termcolor

As a rule of thumb, only the following colors are allowed:

  • grey
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white

One could also use default, that being the default color of the terminal.

Use of stderr

The program uses the stderr stream to print the mask while uses the Getch function to take input characters. This allows the program to easily surpass any pipes or redirections in the terminal as long as the redirections/pipes involve stdout and not stderr.

No Interference while redirecting, storing or piping output

If you wish to instead use the stdout, or output the password to a filestream, change the stream parameter of the getpass function to sys.stdout or a filehandle.

License

The program uses the MIT License.

Bugs

Bugs can be raised in issues. For any improvements, please fork the project. If you feel your fork is better than this project and should be used as a substitute instead, mail me at dev@aniruddh.ml and I will set a pointer over at this project to yours.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpass-2.1.0.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

gpass-2.1.0-py3-none-any.whl (5.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page