other/password.py: alternative_password_generator ignores the requested length when the required characters exceed it
Maintainer thường phản hồi trong vòng 2 ngày
@raaj-2222 đang làm issue này rồi.
Từ ngày 25/10/2026.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 85/100
Hướng nghiên cứu
Mở other/password.py và đọc alternative_password_generator; lỗi nằm trong khối i -= len(chars_incl) / quotient = i // 3 / remainder = i % 3, hoạt động sai khi i trở thành số âm. Tái hiện bằng các đoạn mã trong issue, sau đó quyết định giữa việc ném ValueError hay giới hạn khi len(chars_incl) > i, và kiểm tra xem main() có cần hiển thị lỗi đó không. Hoàn thành nghĩa là cả hai trường hợp tá hiện đều trả về độ dài được yêu cầu và hành vi hiện tại với đầu vào hợp lệ không thay đổi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Repository commit
6e03a48579ca212a08b36be00378f887dc41a003
Python version (python --version)
Python 3.13.5
Dependencies version (pip freeze)
None needed — other/password.py only uses the standard library (secrets, random, string).
Expected behavior
alternative_password_generator(chars_incl, i) should return a password whose length matches the requested length i (the main() prompt calls it "the max length of your password", and the comment above the function says i = how many letters or characters the password length will be).
Actual behavior
When chars_incl is longer than the requested length i, the subtraction i -= len(chars_incl) makes i negative, and the generator silently returns a password longer than what was asked for:
>>> from other.password import alternative_password_generator
>>> len(alternative_password_generator("abcdefgh", 5)) # asked for 5
8
>>> len(alternative_password_generator("abcd", 3)) # asked for 3
5
In the second case i becomes -1, so quotient = i // 3 is -1 and remainder = i % 3 is 2 (Python's modulo of a negative number is positive), which adds one extra random letter on top of all the required characters.
A user who types a max length smaller than their required-characters string in main() gets a password that silently exceeds the max length they asked for. If the requested length is at least len(chars_incl) everything works as expected.
Steps to reproduce
python - <<'EOF'
from other.password import alternative_password_generator
print(len(alternative_password_generator("abcdefgh", 5))) # expected 5, prints 8
print(len(alternative_password_generator("abcd", 3))) # expected 3, prints 5
EOF
Suspected cause
The negative remainder path in alternative_password_generator:
i -= len(chars_incl)
quotient = i // 3
remainder = i % 3
When len(chars_incl) > i, quotient goes negative (the random() calls then contribute nothing because range() of a negative is empty) while remainder stays positive, so quotient + remainder adds extra characters. Guarding the input (if i < len(chars_incl): raise ValueError(...) or clamping) would keep the generator honest about the requested length.
- Ngôn ngữ chính
- Python
- Star
- 225k
- Fork
- 51.2k
- Merge trung bình
- 1 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 32
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TheAlgorithms/Python
-
binomial_distribution overflows at 171 trials even when the result is representableCó thể đã có người làm @landfvit đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
TheAlgorithms/Python#15656 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
continued_fraction uses float division, producing invalid terms for large integers and raising OverflowErrorCó thể đã có người làm @trleo đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
TheAlgorithms/Python#15655 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
ciphers/base32.py and ciphers/base85.py encode Unicode code points instead of bytes: output diverges from the spec for non-ASCII, round-trips corrupt chars >= U+0400, arbitrary bytes crashCó thể đã có người làm @Nate-br đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
TheAlgorithms/Python#15636 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
ciphers/des_ecb.py: encrypt/decrypt silently corrupts any character above U+00FF (round-trip fails)Có thể đã có người làm @mohammedanasnakhuda đã nhận 3 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
TheAlgorithms/Python#15634 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
ciphers/base58.py is a copy of base64_cipher.py — no Base58 implementation exists in the fileCó thể đã có người làm @SakshiYeole đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
TheAlgorithms/Python#15637 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của TheAlgorithms/Python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[oblt-aw][autodoc] Document obs-aw-automerge contract and fix automerge doc inconsistenciesCó thể đã có người làm @github-actions đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
admission-deferred priority: medium status: ready work-class: scoped
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
melodic-software/claude-code-plugins#10887 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
backend bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
PoCInnovation/Distribox#255 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
google/langextract#598 ·
Maintainer thường phản hồi trong vòng 1 ngày