Skip to content

Commit 4feca77

Browse files
author
Mathieu Payrol
committed
fix: correctly handle salt=0 in encrypt_cisco_type7
The function `encrypt_cisco_type7` was incorrectly handling the integer `0` as a missing argument because of the thruthiness check (`if not salt:`). This resulted in a random salt being used when the user explicitely requested salt `0`. The condition has been updated to `if salt is None` to differentiate between a provided `0` and the default `None`.
1 parent 985fd84 commit 4feca77

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

netutils/password.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def encrypt_cisco_type7(unencrypted_password: str, salt: t.Optional[int] = None)
292292
if len(unencrypted_password) > ENCRYPT_TYPE7_LENGTH:
293293
raise ValueError("Password must not exceed 25 characters.")
294294

295-
if not salt:
295+
if salt is None:
296296
salt = random.randint(0, 15) # noqa: S311
297297
# Start building the encrypted password - pre-pend the 2 decimal digit offset.
298298
encrypted_password = format(salt, "02d")

0 commit comments

Comments
 (0)