{"id":20940406,"url":"https://github.com/fedora-python/crypt_r","last_synced_at":"2025-05-13T22:32:17.724Z","repository":{"id":236060126,"uuid":"791825088","full_name":"fedora-python/crypt_r","owner":"fedora-python","description":"A copy of the crypt module that was removed in Python 3.13","archived":false,"fork":false,"pushed_at":"2024-11-04T14:23:43.000Z","size":290,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-14T07:06:43.989Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fedora-python.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-25T12:52:57.000Z","updated_at":"2024-11-04T14:23:46.000Z","dependencies_parsed_at":"2024-05-03T10:00:14.156Z","dependency_job_id":"2e4942dd-1515-4353-b492-8b2e9da837b1","html_url":"https://github.com/fedora-python/crypt_r","commit_stats":null,"previous_names":["fedora-python/crypt"],"tags_count":566,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fedora-python%2Fcrypt_r","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fedora-python%2Fcrypt_r/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fedora-python%2Fcrypt_r/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fedora-python%2Fcrypt_r/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fedora-python","download_url":"https://codeload.github.com/fedora-python/crypt_r/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254036821,"owners_count":22003659,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T23:10:13.739Z","updated_at":"2025-05-13T22:32:16.752Z","avatar_url":"https://github.com/fedora-python.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"crypt_r --- Function to check Unix passwords\n============================================\n\nOriginally by: Steven D. Majewski \u003csdm7g@virginia.edu\u003e\n\nThe ``crypt_r`` module is a renamed copy of the ``crypt`` module\nas it was present in Python 3.12 before it was removed.\n\nSee `PEP 594`_ for details of the removal.\n\nUnlike ``crypt``, this library always exposes the `crypt_r(3)`_ function, not `crypt(3)`_.\n\nNote that ``crypt_r`` is not part of any standard.\nThis library is tested with the ``crypt_r`` implementation in Fedora Linux\n(libxcrypt, as of 2024), and should work with compatible implementations of ``crypt_r``\n(such as ``libcrypt.so`` from older glibc).\n\nNote that the improvements in ``crypt_r`` over ``crypt`` are in memory management and thread safety,\nnot security/cryptography.\n\nIt is easy to use ``crypt_r`` in an insecure way. Notably:\nAll hashing methods except ``METHOD_CRYPT`` (the original Unix algorithm from the 1970s)\nare optional platform-specific extensions.\nThis library does not expose modern hashing methods like libxcrypt's yescrypt.\nThe last wrapper update is from 2017.\nNo future development is planned.\n\nTo use this module, you can either import ``crypt_r`` explicitly\nor use the old ``crypt`` name for backward compatibility.\nHowever, on Python older than 3.13, the ``crypt`` module\nfrom the standard library will usually take precedence on ``sys.path``.\n\nHere follows the original documentation for the removed ``crypt`` module,\nupdated to refer to it as ``crypt_r``:\n\n--------------\n\nThis module implements an interface to the `crypt_r(3)`_ routine, which is\na one-way hash function based upon a modified DES algorithm; see the Unix man\npage for further details.  Possible uses include storing hashed passwords\nso you can check passwords without storing the actual password, or attempting\nto crack Unix passwords with a dictionary.\n\nNotice that the behavior of this module depends on the actual implementation  of\nthe `crypt_r(3)`_ routine in the running system.  Therefore, any\nextensions available on the current implementation will also  be available on\nthis module.\n\nHashing Methods\n---------------\n\nNew in Python 3.3.\n\nThe ``crypt_r`` module defines the list of hashing methods (not all methods\nare available on all platforms):\n\n``METHOD_SHA512``\n   A Modular Crypt Format method with 16 character salt and 86 character\n   hash based on the SHA-512 hash function.  This is the strongest method.\n\n``METHOD_SHA256``\n   Another Modular Crypt Format method with 16 character salt and 43\n   character hash based on the SHA-256 hash function.\n\n``METHOD_BLOWFISH``\n   Another Modular Crypt Format method with 22 character salt and 31\n   character hash based on the Blowfish cipher.\n\n   New in Python 3.7.\n\n``METHOD_MD5``\n   Another Modular Crypt Format method with 8 character salt and 22\n   character hash based on the MD5 hash function.\n\n``METHOD_CRYPT``\n   The traditional method with a 2 character salt and 13 characters of\n   hash.  This is the weakest method.\n\n\nModule Attributes\n-----------------\n\nNew in Python 3.3.\n\n``methods``\n   A list of available password hashing algorithms, as\n   ``crypt_r.METHOD_*`` objects.  This list is sorted from strongest to\n   weakest.\n\n\nModule Functions\n----------------\n\nThe ``crypt_r`` module defines the following functions:\n\n``crypt(word, salt=None)``\n   *word* will usually be a user's password as typed at a prompt or  in a graphical\n   interface.  The optional *salt* is either a string as returned from\n   ``mksalt()``, one of the ``crypt_r.METHOD_*`` values (though not all\n   may be available on all platforms), or a full encrypted password\n   including salt, as returned by this function.  If *salt* is not\n   provided, the strongest method available in ``methods`` will be used.\n\n   Checking a password is usually done by passing the plain-text password\n   as *word* and the full results of a previous  ``crypt``  call,\n   which should be the same as the results of this call.\n\n   *salt* (either a random 2 or 16 character string, possibly prefixed with\n   ``$digit$`` to indicate the method) which will be used to perturb the\n   encryption algorithm.  The characters in *salt* must be in the set\n   ``[./a-zA-Z0-9]``, with the exception of Modular Crypt Format which\n   prefixes a ``$digit$``.\n\n   Returns the hashed password as a string, which will be composed of\n   characters from the same alphabet as the salt.\n\n   Since a few `crypt_r(3)`_ extensions allow different values, with\n   different sizes in the *salt*, it is recommended to use  the full crypted\n   password as salt when checking for a password.\n\n   Changed in Python 3.3:\n   Accept ``crypt_r.METHOD_*`` values in addition to strings for *salt*.\n\n\n``mksalt(method=None, *, rounds=None)``\n   Return a randomly generated salt of the specified method.  If no\n   *method* is given, the strongest method available in ``methods`` is\n   used.\n\n   The return value is a string suitable for passing as the *salt* argument\n   to  ``crypt`` .\n\n   *rounds* specifies the number of rounds for ``METHOD_SHA256``,\n   ``METHOD_SHA512`` and ``METHOD_BLOWFISH``.\n   For ``METHOD_SHA256`` and ``METHOD_SHA512`` it must be an integer between\n   ``1000`` and ``999_999_999``, the default is ``5000``.  For\n   ``METHOD_BLOWFISH`` it must be a power of two between ``16`` (2\\ :sup:`4`)\n   and ``2_147_483_648`` (2\\ :sup:`31`), the default is ``4096``\n   (2\\ :sup:`12`).\n\n   New in Python 3.3.\n\n   Changed in Python 3.7:\n   Added the *rounds* parameter.\n\n\nExamples\n--------\n\nA simple example illustrating typical use (a constant-time comparison\noperation is needed to limit exposure to timing attacks.\n`hmac.compare_digest()`_ is suitable for this purpose):\n\n.. code-block:: python\n\n   import pwd\n   import crypt_r\n   import getpass\n   from hmac import compare_digest as compare_hash\n\n   def login():\n       username = input('Python login: ')\n       cryptedpasswd = pwd.getpwnam(username)[1]\n       if cryptedpasswd:\n           if cryptedpasswd == 'x' or cryptedpasswd == '*':\n               raise ValueError('no support for shadow passwords')\n           cleartext = getpass.getpass()\n           return compare_hash(crypt_r.crypt(cleartext, cryptedpasswd), cryptedpasswd)\n       else:\n           return True\n\nTo generate a hash of a password using the strongest available method and\ncheck it against the original:\n\n.. code-block:: python\n\n   import crypt_r\n   from hmac import compare_digest as compare_hash\n\n   hashed = crypt_r.crypt(plaintext)\n   if not compare_hash(hashed, crypt_r.crypt(plaintext, hashed)):\n       raise ValueError(\"hashed version doesn't validate against original\")\n\n--------------\n\n\nChangelog\n---------\n\n3.13.1\n^^^^^^\n\n* Fix build with ``-Werror=incompatible-pointer-types``\n\n\n3.13.0\n^^^^^^\n\n* Initial fork from CPython 3.12.3\n* Always uses the `crypt_r(3)`_ function, never `crypt(3)`_\n* Renamed the Python modules to ``crypt_r`` and ``_crypt_r``\n\nFor historical changes when this module was included in Python,\nplease refer to the `Python 3.12 Changelog`_.\n\n\n.. _PEP 594: https://peps.python.org/pep-0594/#crypt\n.. _crypt(3): https://manpages.debian.org/crypt(3)\n.. _crypt_r(3): https://manpages.debian.org/crypt_r(3)\n.. _hmac.compare_digest(): https://docs.python.org/3/library/hmac.html#hmac.compare_digest\n.. _Python 3.12 Changelog: https://docs.python.org/3.12/whatsnew/changelog.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffedora-python%2Fcrypt_r","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffedora-python%2Fcrypt_r","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffedora-python%2Fcrypt_r/lists"}