Metadata-Version: 2.1
Name: py-purecrypt
Version: 0.0.3
Summary: A pure Python implementation of crypt(3) from GNU libc
Author: Carl Harris
License: Copyright 2023 Carl E. Harris Jr.
        
        Permission is hereby granted, free of charge, to any person obtaining a
        copy of this software and associated documentation files (the “Software”),
        to deal in the Software without restriction, including without limitation
        the rights to use, copy, modify, merge, publish, distribute, sublicense,
        and/or sell copies of the Software, and to permit persons to whom the
        Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in
        all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cryptography

py-purecrypt
============

A pure Python implementation of the crypt(3) function provided in the GNU C 
library (glibc). This implementation supports the MD5, SHA256, and SHA512 
variants.

Because this is written in pure Python and depends only on the 
[cryptography](https://pypi.org/project/cryptography/) package, it should 
run on any platform supported by Python.

This implementation is not fast. If you're looking for speed, I suggest you
consider alternatives such as [bcrypt](https://pypi.org/project/bcrypt/).


Installation
------------

Install `py-purecrypt` from [PyPI](https://pypi.org/project/py-purecrypt)
using `pip` or your preferred Python package manager.


Usage
-----

This section shows basic usage examples.

### Encrypt a password

Choose a method and generate a salt, then encrypt.

```python
from purecrypt import Crypt, Method

plaintext_password = "super secret"
salt = Crypt.generate_salt(Method.SHA512)
ciphertext_password = Crypt.encrypt(plaintext_password, salt)
```

When generating a salt you can specify the number of rounds to perform
while encrypting.

```python
from purecrypt import Crypt, Method

plaintext_password = "super secret"
salt = Crypt.generate_salt(Method.SHA256, rounds=10000)
ciphertext_password = Crypt.encrypt(plaintext_password, salt)
```

### Validate a password

To validate a given password, you just need the ciphertext that was produced
when the original password was encrypted.

```python
from purecrypt import Crypt

# as produced by the previous example
ciphertext_password = "$5$rounds=10000$vGuBkkhnTmd9BHeFpw4vxHNHJ1bxFRZX$2xiip3lO0cjGg3tZMdled9LpChHk1nmpF6hU6ZW05W1"

plaintext_password = "super secret"
assert Crypt.is_valid(plaintext_password, ciphertext_password)
```


