Skip to content

Commit

Permalink
Replace random.choice with secrets.choice
Browse files Browse the repository at this point in the history
  • Loading branch information
fedecalendino committed May 4, 2024
1 parent 22fc24a commit 6c0a915
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
</dict>
</array>
<key>version</key>
<string>1.8.0</string>
<string>1.9.0</string>
<key>webaddress</key>
<string>https://github.com/fedecalendino/alfred-pwd-gen</string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "Password Generator"
version = "1.8.0"
version = "1.9.0"
description = "Generate secure passwords"
documentation = "https://github.com/fedecalendino/alfred-pwd-gen/blob/main/README.md"
homepage = "https://github.com/fedecalendino/alfred-pwd-gen"
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
alfred-pyflow==0.4.6 ; python_version >= "3.8" and python_version < "3.12"
certifi==2023.11.17 ; python_version >= "3.8" and python_version < "3.12"
charset-normalizer==3.3.2 ; python_version >= "3.8" and python_version < "3.12"
idna==3.6 ; python_version >= "3.8" and python_version < "3.12"
requests==2.31.0 ; python_version >= "3.8" and python_version < "3.12"
urllib3==1.26.6 ; python_version >= "3.8" and python_version < "3.12"
5 changes: 2 additions & 3 deletions src/generator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import random

import secrets
from math import log


LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
DIGITS = "0123456789"
SYMBOLS = "!#$%&*+,-.:;<=>?@^_`~|"
Expand All @@ -12,7 +11,7 @@ def generate(letters: int, digits: int, symbols: int):
characters = []

for amount, space in [(letters, LETTERS), (digits, DIGITS), (symbols, SYMBOLS)]:
tmp = (random.choice(space) for _ in range(amount))
tmp = (secrets.choice(space) for _ in range(amount))
characters.extend(tmp)

random.shuffle(characters)
Expand Down
4 changes: 2 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def format_number(value: int, name: str) -> str:


def parse_args(args: List[str]):
values = [10, 3, 3]
values = [15, 6, 6]

try:
for i, value in enumerate(args):
Expand All @@ -79,7 +79,7 @@ def increment(value: int, inc: int) -> int:
def main(workflow: Workflow):
letters, digits, symbols = parse_args(workflow.args)

for x in range(6):
for x in [0, 0, -2, -1, 1, 2]:
l = increment(letters, x)
d = increment(digits, x)
s = increment(symbols, x)
Expand Down

0 comments on commit 6c0a915

Please sign in to comment.