Skip to main content

getpass alternative with masking, Spyder support and additional features

Project description

Maskpass

Maskpass is a Python library like getpass but with advanced features like masking and reveal/un-reveal.
It also works in Spyder IDE

Installation

Use the package manager pip to install maskpass.

pip install maskpass

It is currently recommended to enforce a version if you have plans to use it in a project, since backward incompatible changes may occur.

Usage

This module contains functions askpass() and advpass()
askpass() uses msvcrt.getch() in windows and altenatives in *nix OS, but it doesn't work in Spyder.

import maskpass
password = maskpass.askpass()

The function returns the entered password in string format
Accepts 2 optional arguments prompt and mask.

Default for prompt is Enter password: . Default for mask is *.
Use mask="" for not echoing anything into the terminal. (Like entering sudo passwords in *nix)

Using advpass()

advpass() uses pynput to get the password, and it works in Spyder too!

import maskpass
password = maskpass.advpass()

The function returns the entered password in string format.

Accepts 4 optional arguments prompt, mask, ide and suppress.

  • prompt is the string to be printed. Default for prompt is Enter password: .

  • mask is the masking character to be used, can be an empty string "", single or multi length character. Default for mask is *.

  • ide expects a bool, it is for overriding IDE check, and has default False. Usually there is no need to change this, since it's automatically checked whether it's running on IDE or terminal. Default is False.

  • suppress expects a bool, is used only in Spyder/QTConsole. Setting this to True prevents the input from being passed to the rest of the system. See pynput documentation for more info. This prevents the Spyder console from jumping down when spacebar is pressed. Default is True .

advpass() also has a revealing feature which will toggle the visibility of the entered password when Left CTRL is pressed. Press it again to change back the visibility.
Note: Only works with advpass() and needs pynput

Exceptions and other returns

In both askpass and advpass, pressing Ctrl+C raise the usual KeyboardInterrupt.

Also, pressing Escape in both functions stops the input and returns an empty string "".

Screenshots

Example GIF

Normal askpass

Spyder Example GIF

advpass in Spyder

Terminal Example GIF

advpass in terminal

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Issues

There is an issue in Spyder where pressing and holding the backspace key yields unpredictable result. This only happens when the key is held down and only in Spyder. Only workaround right now is to backspace letter by letter and not hold it down.

Spyder Backspace Bug

Holding down backspace in advpass in Spyder

Currently I have only tested it in Windows 10, Manjaro and Parrot, so I'm not sure it works in macOS.

This will not work in Jupyter Notebook correctly. Haven't tested it in PyCharm yet, so it might work.

Tips

In some platforms, namely Termux in Android, maskpass does not get installed because pynput cannot install in that. In those platform (or in cases where you don't need advpass), if you would like to use only askpass, just copy both /maskpass/input_methods/without_pynput.py and /maskpass/input_methods/cross_getch to your desired location and you can use askpass using from without_pynput import askpass

License

MIT License

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

maskpass-0.3.7.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

maskpass-0.3.7-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file maskpass-0.3.7.tar.gz.

File metadata

  • Download URL: maskpass-0.3.7.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for maskpass-0.3.7.tar.gz
Algorithm Hash digest
SHA256 73448856147a611cb7c9d98ff417f1e55884419e0864504584e0db9c6a57b60c
MD5 ebf2122b042cb0ae8bc226483af8a739
BLAKE2b-256 9ba086f6cc00295c439a68bb0d792362c0f795c8de6519b18b20cc59412f7317

See more details on using hashes here.

File details

Details for the file maskpass-0.3.7-py3-none-any.whl.

File metadata

  • Download URL: maskpass-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for maskpass-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 49a9b46ae3838f21040c81d169cf2dca0b946881e1b44c0c55df9e2d50f7b623
MD5 eb279e133c2df24263c67b67727a5638
BLAKE2b-256 8879806ef4bf8669a42bde98b7a3a01784acb3769de82f7a5c76ab425edb09cd

See more details on using hashes here.

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