random-password-generator 2.2.0__tar.gz → 3.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- random_password_generator-3.0.0/LICENSE +20 -0
- random_password_generator-3.0.0/PKG-INFO +134 -0
- random_password_generator-3.0.0/README.md +115 -0
- random_password_generator-3.0.0/password_generator.py +182 -0
- random_password_generator-3.0.0/pyproject.toml +25 -0
- random_password_generator-3.0.0/random_password_generator.egg-info/PKG-INFO +134 -0
- {random-password-generator-2.2.0 → random_password_generator-3.0.0}/random_password_generator.egg-info/SOURCES.txt +1 -0
- {random-password-generator-2.2.0 → random_password_generator-3.0.0}/setup.py +3 -2
- random-password-generator-2.2.0/LICENSE +0 -21
- random-password-generator-2.2.0/PKG-INFO +0 -127
- random-password-generator-2.2.0/README.md +0 -102
- random-password-generator-2.2.0/password_generator.py +0 -160
- random-password-generator-2.2.0/random_password_generator.egg-info/PKG-INFO +0 -127
- {random-password-generator-2.2.0 → random_password_generator-3.0.0}/MANIFEST.in +0 -0
- {random-password-generator-2.2.0 → random_password_generator-3.0.0}/random_password_generator.egg-info/dependency_links.txt +0 -0
- {random-password-generator-2.2.0 → random_password_generator-3.0.0}/random_password_generator.egg-info/top_level.txt +0 -0
- {random-password-generator-2.2.0 → random_password_generator-3.0.0}/setup.cfg +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2018-2023 Surya Teja Reddy V
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: random-password-generator
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: A configurable, dependency-free password generator for Python
|
|
5
|
+
Home-page: https://github.com/suryasr007/random-password-generator
|
|
6
|
+
Author: Surya Teja Reddy Valluri
|
|
7
|
+
Author-email: 94suryateja@gmail.com
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Project-URL: Repository, https://github.com/suryasr007/random-password-generator
|
|
10
|
+
Project-URL: Issues, https://github.com/suryasr007/random-password-generator/issues
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: author
|
|
15
|
+
Dynamic: author-email
|
|
16
|
+
Dynamic: home-page
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
Dynamic: requires-python
|
|
19
|
+
|
|
20
|
+
# Random Password Generator
|
|
21
|
+
|
|
22
|
+
[](https://pypi.org/project/random-password-generator/)
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
Install the published package from [PyPI](https://pypi.org/project/random-password-generator/):
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
python -m pip install random-password-generator
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
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.
|
|
35
|
+
|
|
36
|
+
### Python compatibility
|
|
37
|
+
|
|
38
|
+
Version 3 requires Python 3.6 or newer. If you need Python 3.5 compatibility, install version 2.2.0:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
python -m pip install random-password-generator==2.2.0
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
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.
|
|
45
|
+
|
|
46
|
+
## Changelog
|
|
47
|
+
|
|
48
|
+
### 3.0.0
|
|
49
|
+
|
|
50
|
+
- **Python support:** Requires Python 3.6 or newer. For Python 3.5, use `2.2.0`.
|
|
51
|
+
- **Secure randomness:** Character selection, length selection, and shuffling now all use the operating system’s secure random source.
|
|
52
|
+
- **Easier configuration:** Pass settings directly to `PasswordGenerator(...)` as keyword arguments. Setting attributes after construction still works.
|
|
53
|
+
- **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.
|
|
54
|
+
|
|
55
|
+
## Quick start
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from password_generator import PasswordGenerator
|
|
59
|
+
|
|
60
|
+
password = PasswordGenerator().generate()
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`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.
|
|
64
|
+
|
|
65
|
+
## Configuration
|
|
66
|
+
|
|
67
|
+
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.
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from password_generator import PasswordGenerator
|
|
71
|
+
|
|
72
|
+
generator = PasswordGenerator(
|
|
73
|
+
minlen=24,
|
|
74
|
+
maxlen=24,
|
|
75
|
+
minuchars=2,
|
|
76
|
+
excludeuchars="IO",
|
|
77
|
+
excludenumbers="01",
|
|
78
|
+
)
|
|
79
|
+
password = generator.generate()
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
| Setting | Description | Default |
|
|
83
|
+
| --- | --- | --- |
|
|
84
|
+
| `minlen` | Minimum password length | `6` |
|
|
85
|
+
| `maxlen` | Maximum password length | `16` |
|
|
86
|
+
| `minuchars` | Minimum number of uppercase letters | `1` |
|
|
87
|
+
| `minlchars` | Minimum number of lowercase letters | `1` |
|
|
88
|
+
| `minnumbers` | Minimum number of digits | `1` |
|
|
89
|
+
| `minschars` | Minimum number of special characters | `1` |
|
|
90
|
+
| `excludeuchars` | Uppercase letters to exclude | `""` |
|
|
91
|
+
| `excludelchars` | Lowercase letters to exclude | `""` |
|
|
92
|
+
| `excludenumbers` | Digits to exclude | `""` |
|
|
93
|
+
| `excludeschars` | Special characters to exclude | `""` |
|
|
94
|
+
|
|
95
|
+
`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`.
|
|
96
|
+
|
|
97
|
+
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.
|
|
98
|
+
|
|
99
|
+
## Other generation methods
|
|
100
|
+
|
|
101
|
+
### Sample from a custom character pool
|
|
102
|
+
|
|
103
|
+
`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.
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from password_generator import PasswordGenerator
|
|
107
|
+
|
|
108
|
+
password = PasswordGenerator().shuffle_password("abc123!@#", 20)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Generate a password without repeated characters
|
|
112
|
+
|
|
113
|
+
`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`.
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from password_generator import PasswordGenerator
|
|
117
|
+
|
|
118
|
+
password = PasswordGenerator().non_duplicate_password(20)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The web app and API are maintained separately in the [`rpg-web` repository](https://github.com/suryasr007/rpg-web).
|
|
122
|
+
|
|
123
|
+
## Contributing
|
|
124
|
+
|
|
125
|
+
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:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
uv run --locked --python 3.11 ruff check
|
|
129
|
+
uv run --locked --python 3.11 --no-dev python -B -m unittest -v
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Random Password Generator
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/random-password-generator/)
|
|
4
|
+
|
|
5
|
+
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.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Install the published package from [PyPI](https://pypi.org/project/random-password-generator/):
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
python -m pip install random-password-generator
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
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.
|
|
16
|
+
|
|
17
|
+
### Python compatibility
|
|
18
|
+
|
|
19
|
+
Version 3 requires Python 3.6 or newer. If you need Python 3.5 compatibility, install version 2.2.0:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
python -m pip install random-password-generator==2.2.0
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
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.
|
|
26
|
+
|
|
27
|
+
## Changelog
|
|
28
|
+
|
|
29
|
+
### 3.0.0
|
|
30
|
+
|
|
31
|
+
- **Python support:** Requires Python 3.6 or newer. For Python 3.5, use `2.2.0`.
|
|
32
|
+
- **Secure randomness:** Character selection, length selection, and shuffling now all use the operating system’s secure random source.
|
|
33
|
+
- **Easier configuration:** Pass settings directly to `PasswordGenerator(...)` as keyword arguments. Setting attributes after construction still works.
|
|
34
|
+
- **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.
|
|
35
|
+
|
|
36
|
+
## Quick start
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from password_generator import PasswordGenerator
|
|
40
|
+
|
|
41
|
+
password = PasswordGenerator().generate()
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
`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.
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
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.
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from password_generator import PasswordGenerator
|
|
52
|
+
|
|
53
|
+
generator = PasswordGenerator(
|
|
54
|
+
minlen=24,
|
|
55
|
+
maxlen=24,
|
|
56
|
+
minuchars=2,
|
|
57
|
+
excludeuchars="IO",
|
|
58
|
+
excludenumbers="01",
|
|
59
|
+
)
|
|
60
|
+
password = generator.generate()
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
| Setting | Description | Default |
|
|
64
|
+
| --- | --- | --- |
|
|
65
|
+
| `minlen` | Minimum password length | `6` |
|
|
66
|
+
| `maxlen` | Maximum password length | `16` |
|
|
67
|
+
| `minuchars` | Minimum number of uppercase letters | `1` |
|
|
68
|
+
| `minlchars` | Minimum number of lowercase letters | `1` |
|
|
69
|
+
| `minnumbers` | Minimum number of digits | `1` |
|
|
70
|
+
| `minschars` | Minimum number of special characters | `1` |
|
|
71
|
+
| `excludeuchars` | Uppercase letters to exclude | `""` |
|
|
72
|
+
| `excludelchars` | Lowercase letters to exclude | `""` |
|
|
73
|
+
| `excludenumbers` | Digits to exclude | `""` |
|
|
74
|
+
| `excludeschars` | Special characters to exclude | `""` |
|
|
75
|
+
|
|
76
|
+
`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`.
|
|
77
|
+
|
|
78
|
+
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.
|
|
79
|
+
|
|
80
|
+
## Other generation methods
|
|
81
|
+
|
|
82
|
+
### Sample from a custom character pool
|
|
83
|
+
|
|
84
|
+
`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.
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from password_generator import PasswordGenerator
|
|
88
|
+
|
|
89
|
+
password = PasswordGenerator().shuffle_password("abc123!@#", 20)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Generate a password without repeated characters
|
|
93
|
+
|
|
94
|
+
`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`.
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from password_generator import PasswordGenerator
|
|
98
|
+
|
|
99
|
+
password = PasswordGenerator().non_duplicate_password(20)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The web app and API are maintained separately in the [`rpg-web` repository](https://github.com/suryasr007/rpg-web).
|
|
103
|
+
|
|
104
|
+
## Contributing
|
|
105
|
+
|
|
106
|
+
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:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
uv run --locked --python 3.11 ruff check
|
|
110
|
+
uv run --locked --python 3.11 --no-dev python -B -m unittest -v
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Author : Surya Teja <suryateja1919@gmail.com>
|
|
3
|
+
Description : Random Password Generator
|
|
4
|
+
Website : https://suryasr007.github.io
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import string
|
|
8
|
+
from copy import deepcopy
|
|
9
|
+
from secrets import SystemRandom
|
|
10
|
+
|
|
11
|
+
_secure_random = SystemRandom()
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class PasswordGenerator:
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
We can set properties such as
|
|
18
|
+
|
|
19
|
+
| minlen | Minimum length of the password | 6\n
|
|
20
|
+
| maxlen | Maximum length of the password | 16\n
|
|
21
|
+
| minuchars | Minimum upper case characters required in password | 1\n
|
|
22
|
+
| minlchars | Minimum lower case characters required in password | 1\n
|
|
23
|
+
| minnumbers | Minimum numbers required in password | 1\n
|
|
24
|
+
| minschars | Minimum special characters in the password | 1\n
|
|
25
|
+
|
|
26
|
+
Methods implemented in this class are
|
|
27
|
+
|
|
28
|
+
generate() : Generates a password using default or custom properties.
|
|
29
|
+
|
|
30
|
+
shuffle_password(password, length) : Shuffle the given charactes to return a password.
|
|
31
|
+
|
|
32
|
+
non_duplicate_password(length) : Generate a non-duplicate key of given length
|
|
33
|
+
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
*,
|
|
39
|
+
minlen: int = 6,
|
|
40
|
+
maxlen: int = 16,
|
|
41
|
+
minuchars: int = 1,
|
|
42
|
+
minlchars: int = 1,
|
|
43
|
+
minnumbers: int = 1,
|
|
44
|
+
minschars: int = 1,
|
|
45
|
+
excludeuchars: str = "",
|
|
46
|
+
excludelchars: str = "",
|
|
47
|
+
excludenumbers: str = "",
|
|
48
|
+
excludeschars: str = "",
|
|
49
|
+
) -> None:
|
|
50
|
+
self.minlen = minlen
|
|
51
|
+
self.maxlen = maxlen
|
|
52
|
+
self.minuchars = minuchars
|
|
53
|
+
self.minlchars = minlchars
|
|
54
|
+
self.minnumbers = minnumbers
|
|
55
|
+
self.minschars = minschars
|
|
56
|
+
self.excludeuchars = excludeuchars
|
|
57
|
+
self.excludelchars = excludelchars
|
|
58
|
+
self.excludenumbers = excludenumbers
|
|
59
|
+
self.excludeschars = excludeschars
|
|
60
|
+
|
|
61
|
+
self.lower_chars = string.ascii_lowercase
|
|
62
|
+
self.upper_chars = string.ascii_uppercase
|
|
63
|
+
self.numbers_list = string.digits
|
|
64
|
+
self._schars = [
|
|
65
|
+
"!",
|
|
66
|
+
"#",
|
|
67
|
+
"$",
|
|
68
|
+
"%",
|
|
69
|
+
"^",
|
|
70
|
+
"&",
|
|
71
|
+
"*",
|
|
72
|
+
"(",
|
|
73
|
+
")",
|
|
74
|
+
",",
|
|
75
|
+
".",
|
|
76
|
+
"-",
|
|
77
|
+
"_",
|
|
78
|
+
"+",
|
|
79
|
+
"=",
|
|
80
|
+
"<",
|
|
81
|
+
">",
|
|
82
|
+
"?",
|
|
83
|
+
]
|
|
84
|
+
self._allchars = (
|
|
85
|
+
list(self.lower_chars)
|
|
86
|
+
+ list(self.upper_chars)
|
|
87
|
+
+ list(self.numbers_list)
|
|
88
|
+
+ self._schars
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
def generate(self) -> str:
|
|
92
|
+
"""Generate a password, raising TypeError or ValueError for invalid settings."""
|
|
93
|
+
for name in ("minlen", "maxlen", "minuchars", "minlchars", "minnumbers", "minschars"):
|
|
94
|
+
value = getattr(self, name)
|
|
95
|
+
if isinstance(value, bool) or not isinstance(value, int):
|
|
96
|
+
raise TypeError(f"{name} must be an integer.")
|
|
97
|
+
if value < 0:
|
|
98
|
+
raise ValueError(f"{name} must be non-negative.")
|
|
99
|
+
|
|
100
|
+
for name in ("excludeuchars", "excludelchars", "excludenumbers", "excludeschars"):
|
|
101
|
+
if not isinstance(getattr(self, name), str):
|
|
102
|
+
raise TypeError(f"{name} must be a string.")
|
|
103
|
+
|
|
104
|
+
if self.minlen > self.maxlen:
|
|
105
|
+
raise ValueError("minlen cannot be greater than maxlen.")
|
|
106
|
+
|
|
107
|
+
required_length = (
|
|
108
|
+
self.minuchars + self.minlchars + self.minnumbers + self.minschars
|
|
109
|
+
)
|
|
110
|
+
if required_length > self.maxlen:
|
|
111
|
+
raise ValueError("Required character counts exceed maxlen.")
|
|
112
|
+
|
|
113
|
+
effective_minlen = max(self.minlen, required_length)
|
|
114
|
+
|
|
115
|
+
categories = (
|
|
116
|
+
("lowercase letters", self.lower_chars, self.excludelchars, self.minlchars),
|
|
117
|
+
("uppercase letters", self.upper_chars, self.excludeuchars, self.minuchars),
|
|
118
|
+
("digits", self.numbers_list, self.excludenumbers, self.minnumbers),
|
|
119
|
+
("special characters", self._schars, self.excludeschars, self.minschars),
|
|
120
|
+
)
|
|
121
|
+
final_pass = []
|
|
122
|
+
for label, characters, excluded, minimum in categories:
|
|
123
|
+
slots = range(minimum)
|
|
124
|
+
if not slots:
|
|
125
|
+
continue
|
|
126
|
+
pool = list(set(characters) - set(excluded))
|
|
127
|
+
if not pool:
|
|
128
|
+
raise ValueError(f"Required {label} are all excluded.")
|
|
129
|
+
for _ in slots:
|
|
130
|
+
final_pass.append(_secure_random.choice(pool))
|
|
131
|
+
|
|
132
|
+
currentpasslen = len(final_pass)
|
|
133
|
+
all_chars = list(
|
|
134
|
+
set(self._allchars)
|
|
135
|
+
- set(
|
|
136
|
+
list(self.excludelchars)
|
|
137
|
+
+ list(self.excludeuchars)
|
|
138
|
+
+ list(self.excludenumbers)
|
|
139
|
+
+ list(self.excludeschars)
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
if len(final_pass) < self.maxlen:
|
|
144
|
+
randlen = _secure_random.randint(effective_minlen, self.maxlen)
|
|
145
|
+
final_pass += [
|
|
146
|
+
_secure_random.choice(all_chars) for i in range(randlen - currentpasslen)
|
|
147
|
+
]
|
|
148
|
+
|
|
149
|
+
_secure_random.shuffle(final_pass)
|
|
150
|
+
return "".join(final_pass)
|
|
151
|
+
|
|
152
|
+
def shuffle_password(self, password: str, maxlen: int) -> str:
|
|
153
|
+
"""Return maxlen characters sampled with replacement from password."""
|
|
154
|
+
if not isinstance(password, str):
|
|
155
|
+
raise TypeError("password must be a string of characters to sample from.")
|
|
156
|
+
if isinstance(maxlen, bool) or not isinstance(maxlen, int):
|
|
157
|
+
raise TypeError("maxlen must be an integer.")
|
|
158
|
+
if maxlen < 0:
|
|
159
|
+
raise ValueError("maxlen must be non-negative.")
|
|
160
|
+
if maxlen and not password:
|
|
161
|
+
raise ValueError("password must not be empty when maxlen is positive.")
|
|
162
|
+
|
|
163
|
+
final_pass = [_secure_random.choice(password) for _ in range(maxlen)]
|
|
164
|
+
_secure_random.shuffle(final_pass)
|
|
165
|
+
return "".join(final_pass)
|
|
166
|
+
|
|
167
|
+
def non_duplicate_password(self, maxlen: int) -> str:
|
|
168
|
+
"""Generate a password with no repeated characters."""
|
|
169
|
+
limit = len(self._allchars)
|
|
170
|
+
if maxlen > limit:
|
|
171
|
+
raise ValueError(f"maxlen cannot exceed {limit} characters.")
|
|
172
|
+
|
|
173
|
+
allchars = deepcopy(self._allchars)
|
|
174
|
+
final_pass = []
|
|
175
|
+
for _ in range(maxlen):
|
|
176
|
+
character = _secure_random.choice(allchars)
|
|
177
|
+
element_index = allchars.index(character)
|
|
178
|
+
final_pass.append(character)
|
|
179
|
+
allchars.pop(element_index)
|
|
180
|
+
|
|
181
|
+
_secure_random.shuffle(final_pass)
|
|
182
|
+
return "".join(final_pass)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.3"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "random-password-generator"
|
|
7
|
+
version = "3.0.0"
|
|
8
|
+
description = "A configurable, dependency-free password generator for Python"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.6"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
dependencies = []
|
|
14
|
+
|
|
15
|
+
[project.urls]
|
|
16
|
+
Repository = "https://github.com/suryasr007/random-password-generator"
|
|
17
|
+
Issues = "https://github.com/suryasr007/random-password-generator/issues"
|
|
18
|
+
|
|
19
|
+
[tool.setuptools]
|
|
20
|
+
py-modules = ["password_generator"]
|
|
21
|
+
|
|
22
|
+
[dependency-groups]
|
|
23
|
+
dev = [
|
|
24
|
+
"ruff>=0.17.6 ; python_full_version >= '3.11'",
|
|
25
|
+
]
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: random-password-generator
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: A configurable, dependency-free password generator for Python
|
|
5
|
+
Home-page: https://github.com/suryasr007/random-password-generator
|
|
6
|
+
Author: Surya Teja Reddy Valluri
|
|
7
|
+
Author-email: 94suryateja@gmail.com
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
Project-URL: Repository, https://github.com/suryasr007/random-password-generator
|
|
10
|
+
Project-URL: Issues, https://github.com/suryasr007/random-password-generator/issues
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Dynamic: author
|
|
15
|
+
Dynamic: author-email
|
|
16
|
+
Dynamic: home-page
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
Dynamic: requires-python
|
|
19
|
+
|
|
20
|
+
# Random Password Generator
|
|
21
|
+
|
|
22
|
+
[](https://pypi.org/project/random-password-generator/)
|
|
23
|
+
|
|
24
|
+
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.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
Install the published package from [PyPI](https://pypi.org/project/random-password-generator/):
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
python -m pip install random-password-generator
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
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.
|
|
35
|
+
|
|
36
|
+
### Python compatibility
|
|
37
|
+
|
|
38
|
+
Version 3 requires Python 3.6 or newer. If you need Python 3.5 compatibility, install version 2.2.0:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
python -m pip install random-password-generator==2.2.0
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
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.
|
|
45
|
+
|
|
46
|
+
## Changelog
|
|
47
|
+
|
|
48
|
+
### 3.0.0
|
|
49
|
+
|
|
50
|
+
- **Python support:** Requires Python 3.6 or newer. For Python 3.5, use `2.2.0`.
|
|
51
|
+
- **Secure randomness:** Character selection, length selection, and shuffling now all use the operating system’s secure random source.
|
|
52
|
+
- **Easier configuration:** Pass settings directly to `PasswordGenerator(...)` as keyword arguments. Setting attributes after construction still works.
|
|
53
|
+
- **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.
|
|
54
|
+
|
|
55
|
+
## Quick start
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from password_generator import PasswordGenerator
|
|
59
|
+
|
|
60
|
+
password = PasswordGenerator().generate()
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`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.
|
|
64
|
+
|
|
65
|
+
## Configuration
|
|
66
|
+
|
|
67
|
+
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.
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from password_generator import PasswordGenerator
|
|
71
|
+
|
|
72
|
+
generator = PasswordGenerator(
|
|
73
|
+
minlen=24,
|
|
74
|
+
maxlen=24,
|
|
75
|
+
minuchars=2,
|
|
76
|
+
excludeuchars="IO",
|
|
77
|
+
excludenumbers="01",
|
|
78
|
+
)
|
|
79
|
+
password = generator.generate()
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
| Setting | Description | Default |
|
|
83
|
+
| --- | --- | --- |
|
|
84
|
+
| `minlen` | Minimum password length | `6` |
|
|
85
|
+
| `maxlen` | Maximum password length | `16` |
|
|
86
|
+
| `minuchars` | Minimum number of uppercase letters | `1` |
|
|
87
|
+
| `minlchars` | Minimum number of lowercase letters | `1` |
|
|
88
|
+
| `minnumbers` | Minimum number of digits | `1` |
|
|
89
|
+
| `minschars` | Minimum number of special characters | `1` |
|
|
90
|
+
| `excludeuchars` | Uppercase letters to exclude | `""` |
|
|
91
|
+
| `excludelchars` | Lowercase letters to exclude | `""` |
|
|
92
|
+
| `excludenumbers` | Digits to exclude | `""` |
|
|
93
|
+
| `excludeschars` | Special characters to exclude | `""` |
|
|
94
|
+
|
|
95
|
+
`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`.
|
|
96
|
+
|
|
97
|
+
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.
|
|
98
|
+
|
|
99
|
+
## Other generation methods
|
|
100
|
+
|
|
101
|
+
### Sample from a custom character pool
|
|
102
|
+
|
|
103
|
+
`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.
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from password_generator import PasswordGenerator
|
|
107
|
+
|
|
108
|
+
password = PasswordGenerator().shuffle_password("abc123!@#", 20)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Generate a password without repeated characters
|
|
112
|
+
|
|
113
|
+
`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`.
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from password_generator import PasswordGenerator
|
|
117
|
+
|
|
118
|
+
password = PasswordGenerator().non_duplicate_password(20)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The web app and API are maintained separately in the [`rpg-web` repository](https://github.com/suryasr007/rpg-web).
|
|
122
|
+
|
|
123
|
+
## Contributing
|
|
124
|
+
|
|
125
|
+
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:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
uv run --locked --python 3.11 ruff check
|
|
129
|
+
uv run --locked --python 3.11 --no-dev python -B -m unittest -v
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
[MIT](LICENSE)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
from setuptools import setup, find_packages
|
|
2
1
|
from codecs import open
|
|
3
2
|
from os import path
|
|
4
3
|
|
|
4
|
+
from setuptools import setup
|
|
5
5
|
|
|
6
6
|
VERSION = 'v2.2.0'
|
|
7
7
|
|
|
@@ -22,6 +22,7 @@ setup(
|
|
|
22
22
|
author_email='94suryateja@gmail.com',
|
|
23
23
|
license='MIT',
|
|
24
24
|
py_modules=['password_generator'],
|
|
25
|
+
python_requires='>=3.6',
|
|
25
26
|
classifiers=[
|
|
26
27
|
# How mature is this project? Common values are
|
|
27
28
|
# 3 - Alpha
|
|
@@ -33,7 +34,7 @@ setup(
|
|
|
33
34
|
'License :: OSI Approved :: MIT License',
|
|
34
35
|
'Natural Language :: English',
|
|
35
36
|
'Programming Language :: Python :: 3',
|
|
36
|
-
'Programming Language :: Python :: 3
|
|
37
|
+
'Programming Language :: Python :: 3 :: Only',
|
|
37
38
|
'Programming Language :: Python :: 3.6',
|
|
38
39
|
'Programming Language :: Python :: 3.7',
|
|
39
40
|
'Topic :: Utilities',
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018 Surya Teja Reddy V
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: random-password-generator
|
|
3
|
-
Version: 2.2.0
|
|
4
|
-
Summary: Simple and custom random password generator for python
|
|
5
|
-
Home-page: https://github.com/suryasr007/random-password-generator
|
|
6
|
-
Author: Surya Teja Reddy Valluri
|
|
7
|
-
Author-email: 94suryateja@gmail.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Keywords: random password generator different lengths
|
|
10
|
-
Platform: UNKNOWN
|
|
11
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
-
Classifier: Intended Audience :: Information Technology
|
|
13
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
-
Classifier: Natural Language :: English
|
|
15
|
-
Classifier: Programming Language :: Python :: 3
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.5
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
19
|
-
Classifier: Topic :: Utilities
|
|
20
|
-
Classifier: Operating System :: POSIX
|
|
21
|
-
Description-Content-Type: text/markdown
|
|
22
|
-
License-File: LICENSE
|
|
23
|
-
|
|
24
|
-
# Random password Generator
|
|
25
|
-
[](https://pypi.org/project/random-password-generator)
|
|
26
|
-
[](https://travis-ci.org/suryasr007/random-password-generator)
|
|
27
|
-
|
|
28
|
-
#### A minimal and custom random password generator.
|
|
29
|
-
* No dependencies.
|
|
30
|
-
* Generate a simple password of default length 6-16.
|
|
31
|
-
* Generate a password with custom properties.
|
|
32
|
-
* Generate a password from given characters.
|
|
33
|
-
* Generate Non Duplicate Password.
|
|
34
|
-
* Available at https://random-pg.herokuapp.com/ (API and WEB versions are available @ https://github.com/suryasr007/rpg-web repo)
|
|
35
|
-
|
|
36
|
-
### [NOTICE] API and WEB versions are now moved to https://github.com/suryasr007/rpg-web
|
|
37
|
-
|
|
38
|
-
## Usage
|
|
39
|
-
* Install the package.
|
|
40
|
-
* Import the package.
|
|
41
|
-
* Create an instance
|
|
42
|
-
* Modify the default properties. (Optional)
|
|
43
|
-
* Generate the password (Default length of password 6-16 unless specified via properties).
|
|
44
|
-
|
|
45
|
-
``` bash
|
|
46
|
-
pip install random-password-generator
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
``` python
|
|
50
|
-
from password_generator import PasswordGenerator
|
|
51
|
-
|
|
52
|
-
pwo = PasswordGenerator()
|
|
53
|
-
pwo.generate()
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
## Configuration
|
|
58
|
-
|
|
59
|
-
| property | Description | Default |
|
|
60
|
-
| ---------- |------------------------------------------------------| ------- |
|
|
61
|
-
| minlen | Minimum length of the password | 6 |
|
|
62
|
-
| maxlen | Maximum length of the password | 16 |
|
|
63
|
-
| minuchars | Minimum upper case characters required in password | 1 |
|
|
64
|
-
| minlchars | Minimum lower case characters required in password | 1 |
|
|
65
|
-
| minnumbers | Minimum numbers required in password | 1 |
|
|
66
|
-
| minschars | Minimum special characters in the password | 1 |
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
## Update V2.2.0
|
|
70
|
-
Application is now minimal(No dependencies). The API and WEB version are moved to https://github.com/suryasr007/rpg-web
|
|
71
|
-
|
|
72
|
-
## Update V2.1.0
|
|
73
|
-
Application uses [secrets](https://docs.python.org/3/library/secrets.html) module instead of `random` module on Python environments above 3.6.
|
|
74
|
-
|
|
75
|
-
## Update V1.1.0
|
|
76
|
-
From version 1.1.0, Characters can be excluded from the required password by setting the properties on PasswordGenerator object
|
|
77
|
-
|
|
78
|
-
example:
|
|
79
|
-
``` python
|
|
80
|
-
pwo = PasswordGenerator()
|
|
81
|
-
|
|
82
|
-
pwo.excludeuchars = "ABCDEFTUVWXY" # (Optional)
|
|
83
|
-
pwo.excludelchars = "abcdefghijkl" # (Optional)
|
|
84
|
-
pwo.excludenumbers = "012345" # (Optional)
|
|
85
|
-
pwo.excludeschars = "!$%^" # (Optional)
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
## Generate a custom password
|
|
90
|
-
``` python
|
|
91
|
-
pwo = PasswordGenerator()
|
|
92
|
-
|
|
93
|
-
# All properties are optional
|
|
94
|
-
pwo.minlen = 30 # (Optional)
|
|
95
|
-
pwo.maxlen = 30 # (Optional)
|
|
96
|
-
pwo.minuchars = 2 # (Optional)
|
|
97
|
-
pwo.minlchars = 3 # (Optional)
|
|
98
|
-
pwo.minnumbers = 1 # (Optional)
|
|
99
|
-
pwo.minschars = 1 # (Optional)
|
|
100
|
-
|
|
101
|
-
pwo.generate()
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
## Generate a password from given characters
|
|
105
|
-
``` python
|
|
106
|
-
pwo = PasswordGenerator()
|
|
107
|
-
|
|
108
|
-
# It takes two arguments
|
|
109
|
-
# required characters and length of required password
|
|
110
|
-
pwo.shuffle_password('sdafasdf#@&^#&234u8', 20)
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
## Generate Non Duplicate Password
|
|
114
|
-
``` python
|
|
115
|
-
pwo = PasswordGenerator()
|
|
116
|
-
|
|
117
|
-
# length of required password
|
|
118
|
-
pwo.non_duplicate_password(20)
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
## Contributions
|
|
122
|
-
Contributions are welcomed via PR.
|
|
123
|
-
|
|
124
|
-
## License
|
|
125
|
-
* [MIT](LICENSE)
|
|
126
|
-
|
|
127
|
-
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
# Random password Generator
|
|
2
|
-
[](https://pypi.org/project/random-password-generator)
|
|
3
|
-
[](https://travis-ci.org/suryasr007/random-password-generator)
|
|
4
|
-
|
|
5
|
-
#### A minimal and custom random password generator.
|
|
6
|
-
* No dependencies.
|
|
7
|
-
* Generate a simple password of default length 6-16.
|
|
8
|
-
* Generate a password with custom properties.
|
|
9
|
-
* Generate a password from given characters.
|
|
10
|
-
* Generate Non Duplicate Password.
|
|
11
|
-
* Available at https://random-pg.herokuapp.com/ (API and WEB versions are available @ https://github.com/suryasr007/rpg-web repo)
|
|
12
|
-
|
|
13
|
-
### [NOTICE] API and WEB versions are now moved to https://github.com/suryasr007/rpg-web
|
|
14
|
-
|
|
15
|
-
## Usage
|
|
16
|
-
* Install the package.
|
|
17
|
-
* Import the package.
|
|
18
|
-
* Create an instance
|
|
19
|
-
* Modify the default properties. (Optional)
|
|
20
|
-
* Generate the password (Default length of password 6-16 unless specified via properties).
|
|
21
|
-
|
|
22
|
-
``` bash
|
|
23
|
-
pip install random-password-generator
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
``` python
|
|
27
|
-
from password_generator import PasswordGenerator
|
|
28
|
-
|
|
29
|
-
pwo = PasswordGenerator()
|
|
30
|
-
pwo.generate()
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
## Configuration
|
|
35
|
-
|
|
36
|
-
| property | Description | Default |
|
|
37
|
-
| ---------- |------------------------------------------------------| ------- |
|
|
38
|
-
| minlen | Minimum length of the password | 6 |
|
|
39
|
-
| maxlen | Maximum length of the password | 16 |
|
|
40
|
-
| minuchars | Minimum upper case characters required in password | 1 |
|
|
41
|
-
| minlchars | Minimum lower case characters required in password | 1 |
|
|
42
|
-
| minnumbers | Minimum numbers required in password | 1 |
|
|
43
|
-
| minschars | Minimum special characters in the password | 1 |
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
## Update V2.2.0
|
|
47
|
-
Application is now minimal(No dependencies). The API and WEB version are moved to https://github.com/suryasr007/rpg-web
|
|
48
|
-
|
|
49
|
-
## Update V2.1.0
|
|
50
|
-
Application uses [secrets](https://docs.python.org/3/library/secrets.html) module instead of `random` module on Python environments above 3.6.
|
|
51
|
-
|
|
52
|
-
## Update V1.1.0
|
|
53
|
-
From version 1.1.0, Characters can be excluded from the required password by setting the properties on PasswordGenerator object
|
|
54
|
-
|
|
55
|
-
example:
|
|
56
|
-
``` python
|
|
57
|
-
pwo = PasswordGenerator()
|
|
58
|
-
|
|
59
|
-
pwo.excludeuchars = "ABCDEFTUVWXY" # (Optional)
|
|
60
|
-
pwo.excludelchars = "abcdefghijkl" # (Optional)
|
|
61
|
-
pwo.excludenumbers = "012345" # (Optional)
|
|
62
|
-
pwo.excludeschars = "!$%^" # (Optional)
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
## Generate a custom password
|
|
67
|
-
``` python
|
|
68
|
-
pwo = PasswordGenerator()
|
|
69
|
-
|
|
70
|
-
# All properties are optional
|
|
71
|
-
pwo.minlen = 30 # (Optional)
|
|
72
|
-
pwo.maxlen = 30 # (Optional)
|
|
73
|
-
pwo.minuchars = 2 # (Optional)
|
|
74
|
-
pwo.minlchars = 3 # (Optional)
|
|
75
|
-
pwo.minnumbers = 1 # (Optional)
|
|
76
|
-
pwo.minschars = 1 # (Optional)
|
|
77
|
-
|
|
78
|
-
pwo.generate()
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## Generate a password from given characters
|
|
82
|
-
``` python
|
|
83
|
-
pwo = PasswordGenerator()
|
|
84
|
-
|
|
85
|
-
# It takes two arguments
|
|
86
|
-
# required characters and length of required password
|
|
87
|
-
pwo.shuffle_password('sdafasdf#@&^#&234u8', 20)
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## Generate Non Duplicate Password
|
|
91
|
-
``` python
|
|
92
|
-
pwo = PasswordGenerator()
|
|
93
|
-
|
|
94
|
-
# length of required password
|
|
95
|
-
pwo.non_duplicate_password(20)
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
## Contributions
|
|
99
|
-
Contributions are welcomed via PR.
|
|
100
|
-
|
|
101
|
-
## License
|
|
102
|
-
* [MIT](LICENSE)
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Author : Surya Teja <suryateja1919@gmail.com>
|
|
3
|
-
Description : Random Password Generator
|
|
4
|
-
Website : https://suryasr007.github.io
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import string
|
|
8
|
-
from copy import deepcopy
|
|
9
|
-
from random import shuffle, randint
|
|
10
|
-
|
|
11
|
-
try:
|
|
12
|
-
from secrets import choice
|
|
13
|
-
except ImportError:
|
|
14
|
-
from random import choice
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class PasswordGenerator:
|
|
18
|
-
"""
|
|
19
|
-
|
|
20
|
-
We can set properties such as
|
|
21
|
-
|
|
22
|
-
| minlen | Minimum length of the password | 6\n
|
|
23
|
-
| maxlen | Maximum length of the password | 16\n
|
|
24
|
-
| minuchars | Minimum upper case characters required in password | 1\n
|
|
25
|
-
| minlchars | Minimum lower case characters required in password | 1\n
|
|
26
|
-
| minnumbers | Minimum numbers required in password | 1\n
|
|
27
|
-
| minschars | Minimum special characters in the password | 1\n
|
|
28
|
-
|
|
29
|
-
Methods implemented in this class are
|
|
30
|
-
|
|
31
|
-
generate() : Generates a password using default or custom propertiesself.
|
|
32
|
-
|
|
33
|
-
shuffle_password(password, length) : Shuffle the given charactes and return a password from given characters.
|
|
34
|
-
|
|
35
|
-
non_duplicate_password(length) : Generate a non duplicate key of givrn length
|
|
36
|
-
|
|
37
|
-
"""
|
|
38
|
-
|
|
39
|
-
def __init__(self):
|
|
40
|
-
self.minlen = 6
|
|
41
|
-
self.maxlen = 16
|
|
42
|
-
self.minuchars = 1
|
|
43
|
-
self.minlchars = 1
|
|
44
|
-
self.minnumbers = 1
|
|
45
|
-
self.minschars = 1
|
|
46
|
-
self.excludeuchars = ""
|
|
47
|
-
self.excludelchars = ""
|
|
48
|
-
self.excludenumbers = ""
|
|
49
|
-
self.excludeschars = ""
|
|
50
|
-
|
|
51
|
-
self.lower_chars = string.ascii_lowercase
|
|
52
|
-
self.upper_chars = string.ascii_uppercase
|
|
53
|
-
self.numbers_list = string.digits
|
|
54
|
-
self._schars = [
|
|
55
|
-
"!",
|
|
56
|
-
"#",
|
|
57
|
-
"$",
|
|
58
|
-
"%",
|
|
59
|
-
"^",
|
|
60
|
-
"&",
|
|
61
|
-
"*",
|
|
62
|
-
"(",
|
|
63
|
-
")",
|
|
64
|
-
",",
|
|
65
|
-
".",
|
|
66
|
-
"-",
|
|
67
|
-
"_",
|
|
68
|
-
"+",
|
|
69
|
-
"=",
|
|
70
|
-
"<",
|
|
71
|
-
">",
|
|
72
|
-
"?",
|
|
73
|
-
]
|
|
74
|
-
self._allchars = (
|
|
75
|
-
list(self.lower_chars)
|
|
76
|
-
+ list(self.upper_chars)
|
|
77
|
-
+ list(self.numbers_list)
|
|
78
|
-
+ self._schars
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
def generate(self):
|
|
82
|
-
"""Generates a password using default or custom properties"""
|
|
83
|
-
if (
|
|
84
|
-
self.minlen < 0
|
|
85
|
-
or self.maxlen < 0
|
|
86
|
-
or self.minuchars < 0
|
|
87
|
-
or self.minlchars < 0
|
|
88
|
-
or self.minnumbers < 0
|
|
89
|
-
or self.minschars < 0
|
|
90
|
-
):
|
|
91
|
-
raise ValueError("Character length should not be negative")
|
|
92
|
-
|
|
93
|
-
if self.minlen > self.maxlen:
|
|
94
|
-
raise ValueError(
|
|
95
|
-
"Minimum length cannot be greater than maximum length. The default maximum length is 16."
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
collectiveMinLength = (
|
|
99
|
-
self.minuchars + self.minlchars + self.minnumbers + self.minschars
|
|
100
|
-
)
|
|
101
|
-
|
|
102
|
-
if collectiveMinLength > self.minlen:
|
|
103
|
-
self.minlen = collectiveMinLength
|
|
104
|
-
|
|
105
|
-
final_pass = [
|
|
106
|
-
choice(list(set(self.lower_chars) - set(self.excludelchars)))
|
|
107
|
-
for i in range(self.minlchars)
|
|
108
|
-
]
|
|
109
|
-
final_pass += [
|
|
110
|
-
choice(list(set(self.upper_chars) - set(self.excludeuchars)))
|
|
111
|
-
for i in range(self.minuchars)
|
|
112
|
-
]
|
|
113
|
-
final_pass += [
|
|
114
|
-
choice(list(set(self.numbers_list) - set(self.excludenumbers)))
|
|
115
|
-
for i in range(self.minnumbers)
|
|
116
|
-
]
|
|
117
|
-
final_pass += [
|
|
118
|
-
choice(list(set(self._schars) - set(self.excludeschars)))
|
|
119
|
-
for i in range(self.minschars)
|
|
120
|
-
]
|
|
121
|
-
|
|
122
|
-
currentpasslen = len(final_pass)
|
|
123
|
-
all_chars = list(
|
|
124
|
-
set(self._allchars)
|
|
125
|
-
- set(
|
|
126
|
-
list(self.excludelchars)
|
|
127
|
-
+ list(self.excludeuchars)
|
|
128
|
-
+ list(self.excludenumbers)
|
|
129
|
-
+ list(self.excludeschars)
|
|
130
|
-
)
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
if len(final_pass) < self.maxlen:
|
|
134
|
-
randlen = randint(self.minlen, self.maxlen)
|
|
135
|
-
final_pass += [choice(all_chars) for i in range(randlen - currentpasslen)]
|
|
136
|
-
|
|
137
|
-
shuffle(final_pass)
|
|
138
|
-
return "".join(final_pass)
|
|
139
|
-
|
|
140
|
-
def shuffle_password(self, password, maxlen):
|
|
141
|
-
"""Shuffle the given charactes and return a password from given characters."""
|
|
142
|
-
final_pass = [choice(list(password)) for i in range(int(maxlen))]
|
|
143
|
-
shuffle(final_pass)
|
|
144
|
-
return "".join(final_pass)
|
|
145
|
-
|
|
146
|
-
def non_duplicate_password(self, maxlen):
|
|
147
|
-
"""Generate a non duplicate key of given length"""
|
|
148
|
-
allchars = deepcopy(self._allchars)
|
|
149
|
-
final_pass = []
|
|
150
|
-
try:
|
|
151
|
-
for i in range(maxlen):
|
|
152
|
-
character = choice(allchars)
|
|
153
|
-
element_index = allchars.index(character)
|
|
154
|
-
final_pass.append(character)
|
|
155
|
-
allchars.pop(element_index)
|
|
156
|
-
except IndexError as e:
|
|
157
|
-
raise ValueError("Length should less than 77 characters.")
|
|
158
|
-
|
|
159
|
-
shuffle(final_pass)
|
|
160
|
-
return "".join(final_pass)
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: random-password-generator
|
|
3
|
-
Version: 2.2.0
|
|
4
|
-
Summary: Simple and custom random password generator for python
|
|
5
|
-
Home-page: https://github.com/suryasr007/random-password-generator
|
|
6
|
-
Author: Surya Teja Reddy Valluri
|
|
7
|
-
Author-email: 94suryateja@gmail.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Keywords: random password generator different lengths
|
|
10
|
-
Platform: UNKNOWN
|
|
11
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
-
Classifier: Intended Audience :: Information Technology
|
|
13
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
-
Classifier: Natural Language :: English
|
|
15
|
-
Classifier: Programming Language :: Python :: 3
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.5
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.7
|
|
19
|
-
Classifier: Topic :: Utilities
|
|
20
|
-
Classifier: Operating System :: POSIX
|
|
21
|
-
Description-Content-Type: text/markdown
|
|
22
|
-
License-File: LICENSE
|
|
23
|
-
|
|
24
|
-
# Random password Generator
|
|
25
|
-
[](https://pypi.org/project/random-password-generator)
|
|
26
|
-
[](https://travis-ci.org/suryasr007/random-password-generator)
|
|
27
|
-
|
|
28
|
-
#### A minimal and custom random password generator.
|
|
29
|
-
* No dependencies.
|
|
30
|
-
* Generate a simple password of default length 6-16.
|
|
31
|
-
* Generate a password with custom properties.
|
|
32
|
-
* Generate a password from given characters.
|
|
33
|
-
* Generate Non Duplicate Password.
|
|
34
|
-
* Available at https://random-pg.herokuapp.com/ (API and WEB versions are available @ https://github.com/suryasr007/rpg-web repo)
|
|
35
|
-
|
|
36
|
-
### [NOTICE] API and WEB versions are now moved to https://github.com/suryasr007/rpg-web
|
|
37
|
-
|
|
38
|
-
## Usage
|
|
39
|
-
* Install the package.
|
|
40
|
-
* Import the package.
|
|
41
|
-
* Create an instance
|
|
42
|
-
* Modify the default properties. (Optional)
|
|
43
|
-
* Generate the password (Default length of password 6-16 unless specified via properties).
|
|
44
|
-
|
|
45
|
-
``` bash
|
|
46
|
-
pip install random-password-generator
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
``` python
|
|
50
|
-
from password_generator import PasswordGenerator
|
|
51
|
-
|
|
52
|
-
pwo = PasswordGenerator()
|
|
53
|
-
pwo.generate()
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
## Configuration
|
|
58
|
-
|
|
59
|
-
| property | Description | Default |
|
|
60
|
-
| ---------- |------------------------------------------------------| ------- |
|
|
61
|
-
| minlen | Minimum length of the password | 6 |
|
|
62
|
-
| maxlen | Maximum length of the password | 16 |
|
|
63
|
-
| minuchars | Minimum upper case characters required in password | 1 |
|
|
64
|
-
| minlchars | Minimum lower case characters required in password | 1 |
|
|
65
|
-
| minnumbers | Minimum numbers required in password | 1 |
|
|
66
|
-
| minschars | Minimum special characters in the password | 1 |
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
## Update V2.2.0
|
|
70
|
-
Application is now minimal(No dependencies). The API and WEB version are moved to https://github.com/suryasr007/rpg-web
|
|
71
|
-
|
|
72
|
-
## Update V2.1.0
|
|
73
|
-
Application uses [secrets](https://docs.python.org/3/library/secrets.html) module instead of `random` module on Python environments above 3.6.
|
|
74
|
-
|
|
75
|
-
## Update V1.1.0
|
|
76
|
-
From version 1.1.0, Characters can be excluded from the required password by setting the properties on PasswordGenerator object
|
|
77
|
-
|
|
78
|
-
example:
|
|
79
|
-
``` python
|
|
80
|
-
pwo = PasswordGenerator()
|
|
81
|
-
|
|
82
|
-
pwo.excludeuchars = "ABCDEFTUVWXY" # (Optional)
|
|
83
|
-
pwo.excludelchars = "abcdefghijkl" # (Optional)
|
|
84
|
-
pwo.excludenumbers = "012345" # (Optional)
|
|
85
|
-
pwo.excludeschars = "!$%^" # (Optional)
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
## Generate a custom password
|
|
90
|
-
``` python
|
|
91
|
-
pwo = PasswordGenerator()
|
|
92
|
-
|
|
93
|
-
# All properties are optional
|
|
94
|
-
pwo.minlen = 30 # (Optional)
|
|
95
|
-
pwo.maxlen = 30 # (Optional)
|
|
96
|
-
pwo.minuchars = 2 # (Optional)
|
|
97
|
-
pwo.minlchars = 3 # (Optional)
|
|
98
|
-
pwo.minnumbers = 1 # (Optional)
|
|
99
|
-
pwo.minschars = 1 # (Optional)
|
|
100
|
-
|
|
101
|
-
pwo.generate()
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
## Generate a password from given characters
|
|
105
|
-
``` python
|
|
106
|
-
pwo = PasswordGenerator()
|
|
107
|
-
|
|
108
|
-
# It takes two arguments
|
|
109
|
-
# required characters and length of required password
|
|
110
|
-
pwo.shuffle_password('sdafasdf#@&^#&234u8', 20)
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
## Generate Non Duplicate Password
|
|
114
|
-
``` python
|
|
115
|
-
pwo = PasswordGenerator()
|
|
116
|
-
|
|
117
|
-
# length of required password
|
|
118
|
-
pwo.non_duplicate_password(20)
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
## Contributions
|
|
122
|
-
Contributions are welcomed via PR.
|
|
123
|
-
|
|
124
|
-
## License
|
|
125
|
-
* [MIT](LICENSE)
|
|
126
|
-
|
|
127
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|