Skip to main content

PRECIS-i18n: Internationalized Usernames and Passwords

Project description

MIT licensed Build Status codecov.io

If you want your application to accept unicode user names and passwords, you must be careful in how you validate and compare them. The PRECIS framework makes internationalized user names and passwords safer for use by applications. PRECIS profiles transform unicode strings into a canonical UTF-8 form, suitable for byte-by-byte comparison.

This module implements the PRECIS Framework as described in:

  • PRECIS Framework: Preparation, Enforcement, and Comparison of Internationalized Strings in Application Protocols (RFC 7564)

  • Preparation, Enforcement, and Comparison of Internationalized Strings Representing Usernames and Passwords (RFC 7613)

  • Preparation, Enforcement, and Comparison of Internationalized Strings Representing Nicknames (RFC 7700)

Requires Python 3.3 or later.

Usage

Import the precis_i18n.codec module to register the PRECIS codec names. Use the encode method with any unicode string. encode will raise a UnicodeEncodeError if the string is disallowed.

>>> import precis_i18n.codec
>>> 'Kevin'.encode('UsernameCasePreserved')
b'Kevin'
>>> '\u212Aevin'.encode('UsernameCasePreserved')
b'Kevin'
>>> '\uFF2Bevin'.encode('UsernameCasePreserved')
b'Kevin'
>>> '\u212Aevin'.encode('UsernameCaseMapped')
b'kevin'
>>> '\uFF2Bevin'.encode('OpaqueString')
b'\xef\xbc\xabevin'
>>> '\U0001F17Aevin'.encode('UsernameCasePreserved')
Traceback (most recent call last):
    ...
UnicodeEncodeError: 'UsernameCasePreserved' codec can't encode character '\U0001f17a' in position 0: DISALLOWED/symbols

Alternatively, you can use a PRECIS profile directly, without installing a codec.

>>> from precis_i18n import get_profile
>>> username = get_profile('UsernameCaseMapped')
>>> username.enforce('Kevin')
b'kevin'
>>> username.enforce('\u212Aevin')
b'kevin'
>>> username.enforce('\uFF2Bevin')
b'kevin'
>>> username.enforce('\U0001F17Aevin')
Traceback (most recent call last):
    ...
UnicodeEncodeError: 'UsernameCaseMapped' codec can't encode character '\U0001f17a' in position 0: DISALLOWED/symbols

Supported Profiles and Codecs

Each PRECIS profile has a corresponding codec name. The CaseMapped variant converts the string to lower case for implementing case-insensitive comparison.

  • UsernameCasePreserved

  • UsernameCaseMapped

  • OpaqueString

  • NicknameCasePreserved

  • NicknameCaseMapped

The CaseMapped profiles use Unicode Default Case Folding. There are additional codecs that use Unicode ToLower to support draft RFC changes.

  • UsernameCaseMapped:ToLower

  • NicknameCaseMapped:ToLower

The PRECIS base string classes are also available:

  • IdentifierClass

  • FreeFormClass

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

precis_i18n-0.4.1.tar.gz (49.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

precis_i18n-0.4.1-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file precis_i18n-0.4.1.tar.gz.

File metadata

  • Download URL: precis_i18n-0.4.1.tar.gz
  • Upload date:
  • Size: 49.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for precis_i18n-0.4.1.tar.gz
Algorithm Hash digest
SHA256 7e429e0a3de7347e6e3b7f1de06474aafd113edb5b56607f54739b4678269863
MD5 2c94464d0891866d99fe9d5a468956a4
BLAKE2b-256 ec327f2b4d88a2696f75d14ee7741d4b97e4d87aba01bda0026a5f8c008da7f4

See more details on using hashes here.

File details

Details for the file precis_i18n-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for precis_i18n-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ee072d7f93c2fb07cb6d6c6f1965a74a98c7196eb03db6099909ceec6e30579a
MD5 295a2ebdc6b9e9260d6aa0b472357011
BLAKE2b-256 0097286941a67ecc2ed80413b901ea0405ba4c82c432b3928d345ae9e2092e3f

See more details on using hashes here.

Supported by

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