Skip to main content

A pythonic wrapper around pinentry for secure password input

Project description

PynEntry

A pythonic wrapper for pinentry

Written mostly to practice metaprogramming

credit to mijikai for a working example

Requires pinentry to be installed

convienience methods:

  • to quickly and simply get a password/pin from a user:

get_pin(description=None, prompt=None, timeout=0, display=None, global_grab=True)

  • to show and get a confirmation from a user:

get_confirm(description=None, timeout=0, display=None, global_grab=True)

  • to show a message to a user:

show_message(description=None, timeout=0, display=None, global_grab=True)

PynEntry class

The above methods instance and configure a PynEntry instance wich can be called and configured manually via attributes

the PynEntry class supports the following attributes:

  • description: Sets the descriptive text to display
  • prompt: Sets the text just before the passphrase entry (ex: "PASS:")
  • title: Sets the window title
  • ok_text: Sets the text shown in the "OK" button
  • cancel_text: Sets the text shown in the "Cancel" button
  • error_text: Sets the text in case of error before reprompt (Cleared after every get_pin() call)
  • tty_name: Chose the tty to use (set automatically)
  • tty_type: Change the tty type to use.
  • locale: Sets the locale to use (set automatically to current os locale)

NOTE: The PynEntry class uses the $PATH variable to find the pinentry executable, you can specify the location of the executable manually when you initialize like so: PynEntry(executable='/path/to/pinentry')

PynEntry is best used as a context manager to automatically kill the pinentry process when you are done.

Example:

import pynentry
pynentry.show_message('Hello there!')

with pynentry.PynEntry() as p:
    p.description = 'Enter a password.\n Choose Wisely!'
    p.prompt = 'PASS>'
    try:
        passwd = p.get_pin()
    except pynentry.PinEntryCancelled:
        print('Cancelled?! Goodbye.')
        exit()
    p.ok_text = 'yep!'
    p.cancel_text = 'nope!'
    p.description = f'CAN YOU CONFIRM YOUR SUPER SECRET PASSWORD IS {passwd}?'
    if p.get_confirm():
            print(f'password {passwd} saved!')
    else:
            print(f'Too bad, so sad')

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pynentry-0.1.7-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file pynentry-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: pynentry-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for pynentry-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 62332b8cd922901f4c9dd7533e84d6f6fac4cc85a3d29fd6d0db49e27e507f21
MD5 f1639fc40ae85fc47f097585d712a546
BLAKE2b-256 d5f0e2d1640edae8d21672b562b936001327ec875264b188e8cba305de239133

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