Metadata-Version: 2.4
Name: random-password-generator
Version: 3.0.0
Summary: A configurable, dependency-free password generator for Python
Home-page: https://github.com/suryasr007/random-password-generator
Author: Surya Teja Reddy Valluri
Author-email: 94suryateja@gmail.com
License-Expression: MIT
Project-URL: Repository, https://github.com/suryasr007/random-password-generator
Project-URL: Issues, https://github.com/suryasr007/random-password-generator/issues
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: author
Dynamic: author-email
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# Random Password Generator

[![PyPI version](https://img.shields.io/pypi/v/random-password-generator)](https://pypi.org/project/random-password-generator/)

A dependency-free Python library for generating passwords with configurable lengths, character requirements, and exclusions. Version 3 uses the operating system’s cryptographically secure randomness for character selection, length selection, and shuffling.

## Installation

Install the published package from [PyPI](https://pypi.org/project/random-password-generator/):

```bash
python -m pip install random-password-generator
```

The examples below describe the version 3 API. To try the code in this repository rather than the published release, run `python -m pip install .` from a local checkout.

### Python compatibility

Version 3 requires Python 3.6 or newer. If you need Python 3.5 compatibility, install version 2.2.0:

```bash
python -m pip install random-password-generator==2.2.0
```

On Python 3.5, version 2.2.0 falls back to a non-cryptographic random number generator. Use version 3 on a supported Python release for security-sensitive passwords.

## Changelog

### 3.0.0

- **Python support:** Requires Python 3.6 or newer. For Python 3.5, use `2.2.0`.
- **Secure randomness:** Character selection, length selection, and shuffling now all use the operating system’s secure random source.
- **Easier configuration:** Pass settings directly to `PasswordGenerator(...)` as keyword arguments. Setting attributes after construction still works.
- **Stricter validation:** `generate()` rejects configurations that cannot meet the length or character requirements. `shuffle_password()` no longer coerces lengths such as `"20"` or `20.0`; pass `20` instead.

## Quick start

```python
from password_generator import PasswordGenerator

password = PasswordGenerator().generate()
```

`generate()` returns a string. By default, it generates a password of 6–16 characters with at least one uppercase letter, one lowercase letter, one digit, and one special character. For a longer password, set `minlen` and `maxlen` to the same value.

## Configuration

Pass settings as optional keyword arguments to `PasswordGenerator()`. Omitted settings keep their defaults, and existing code can still change the attributes after creating an instance.

```python
from password_generator import PasswordGenerator

generator = PasswordGenerator(
    minlen=24,
    maxlen=24,
    minuchars=2,
    excludeuchars="IO",
    excludenumbers="01",
)
password = generator.generate()
```

| Setting | Description | Default |
| --- | --- | --- |
| `minlen` | Minimum password length | `6` |
| `maxlen` | Maximum password length | `16` |
| `minuchars` | Minimum number of uppercase letters | `1` |
| `minlchars` | Minimum number of lowercase letters | `1` |
| `minnumbers` | Minimum number of digits | `1` |
| `minschars` | Minimum number of special characters | `1` |
| `excludeuchars` | Uppercase letters to exclude | `""` |
| `excludelchars` | Lowercase letters to exclude | `""` |
| `excludenumbers` | Digits to exclude | `""` |
| `excludeschars` | Special characters to exclude | `""` |

`generate()` checks these settings when called. Lengths and counts must be non-negative integers (not booleans), and exclusions must be strings. Wrong types raise `TypeError`. Negative values, `minlen` greater than `maxlen`, or minimum counts that add up to more than `maxlen` raise `ValueError`.

If exclusions leave a required category empty, `generate()` raises a `ValueError` that names the category. Setting a category’s minimum to `0` makes it optional; to omit it entirely, also exclude all its characters.

## Other generation methods

### Sample from a custom character pool

`shuffle_password(password, maxlen)` samples from the supplied string **with replacement**. Characters can repeat, and the result can be longer than the input. `maxlen` is the exact output length and must be a non-negative integer, not a boolean. A length of `0` returns `""`; a positive length requires a non-empty character string.

```python
from password_generator import PasswordGenerator

password = PasswordGenerator().shuffle_password("abc123!@#", 20)
```

### Generate a password without repeated characters

`non_duplicate_password(maxlen)` draws from the built-in pool of 80 distinct characters. A length of 80 is valid; a longer request raises `ValueError`.

```python
from password_generator import PasswordGenerator

password = PasswordGenerator().non_duplicate_password(20)
```

The web app and API are maintained separately in the [`rpg-web` repository](https://github.com/suryasr007/rpg-web).

## Contributing

Pull requests are welcome. GitHub Actions runs Ruff and the unit tests on pull requests targeting `main`. To run the same checks locally from the repository root:

```bash
uv run --locked --python 3.11 ruff check
uv run --locked --python 3.11 --no-dev python -B -m unittest -v
```

## License

[MIT](LICENSE)
