Passwords¶
netutils.password
¶
Functions for working with Passwords.
compare_cisco_type5(unencrypted_password, encrypted_password, return_original=False)
¶
Given an encrypted and unencrypted password of Cisco Type 5 password, compare if they are a match.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unencrypted_password |
str
|
A password that has not been encrypted, and will be compared against. |
required |
encrypted_password |
str
|
A password that has been encrypted. |
required |
return_original |
bool
|
Whether or not to return the original, this is helpful when used to populate the configuration. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Union[str, bool]
|
Whether or not the password is as compared to. |
Examples:
>>> from netutils.password import compare_cisco_type5
>>> compare_cisco_type5("cisco","$1$nTc1$Z28sUTcWfXlvVe2x.3XAa.")
True
>>> compare_cisco_type5("not_cisco","$1$nTc1$Z28sUTcWfXlvVe2x.3XAa.")
False
>>>
Source code in netutils/password.py
compare_cisco_type7(unencrypted_password, encrypted_password, return_original=False)
¶
Given an encrypted and unencrypted password of Cisco Type 7 password, compare if they are a match.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unencrypted_password |
str
|
A password that has not been encrypted, and will be compared against. |
required |
encrypted_password |
str
|
A password that has been encrypted. |
required |
return_original |
bool
|
Whether or not to return the original, this is helpful when used to populate the configuration. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Union[str, bool]
|
Whether or not the password is as compared to. |
Examples:
>>> from netutils.password import compare_cisco_type7
>>> compare_cisco_type7("cisco","121A0C041104")
True
>>> compare_cisco_type7("not_cisco","121A0C041104")
False
>>>
Source code in netutils/password.py
compare_cisco_type9(unencrypted_password, encrypted_password, return_original=False)
¶
Given an encrypted and unencrypted password of Cisco Type 9 password, compare if they are a match.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unencrypted_password |
str
|
A password that has not been encrypted, and will be compared against. |
required |
encrypted_password |
str
|
A password that has been encrypted. |
required |
return_original |
bool
|
Whether or not to return the original, this is helpful when used to populate the configuration. Defaults to False. |
False
|
Returns:
Type | Description |
---|---|
Union[str, bool]
|
Whether or not the password is as compared to. |
Examples:
>>> from netutils.password import compare_cisco_type9
>>> compare_cisco_type9("cisco","$9$588|P!iWqEx=Wf$nadLmT9snc6V9QAeUuATSOoCAZMQIHqixJfZpQj5EU2")
True
>>> compare_cisco_type9("not_cisco","$9$588|P!iWqEx=Wf$nadLmT9snc6V9QAeUuATSOoCAZMQIHqixJfZpQj5EU2")
False
>>>
Source code in netutils/password.py
decrypt_cisco_type7(encrypted_password)
¶
Given an unencrypted password of Cisco Type 7 password decrypt it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encrypted_password |
str
|
A password that has been encrypted, and will be decrypted. |
required |
Returns:
Type | Description |
---|---|
str
|
The unencrypted_password password. |
Examples:
>>> from netutils.password import decrypt_cisco_type7
>>> decrypt_cisco_type7("121A0C041104")
'cisco'
>>>
Source code in netutils/password.py
decrypt_juniper_type9(encrypted_password)
¶
Given an encrypted Junos $9$ type password, decrypt it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encrypted_password |
str
|
A password that has been encrypted, and will be decrypted. |
required |
Returns:
Type | Description |
---|---|
str
|
The unencrypted_password password. |
Examples:
>>> from netutils.password import decrypt_juniper_type9
>>> decrypt_juniper_type9("$9$7YdwgGDkTz6oJz69A1INdb")
'juniper'
>>>
Source code in netutils/password.py
encrypt_cisco_type5(unencrypted_password, salt=None, salt_len=4)
¶
Given an unencrypted password of Cisco Type 5 password, encrypt it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unencrypted_password |
str
|
A password that has not been encrypted, and will be compared against. |
required |
salt |
Optional[str]
|
A random set of characters that can be set by the operator. Defaults to random generated one. |
None
|
salt_len |
int
|
The number of random set of characters, when not manually set. Defaults to 4. |
4
|
Returns:
Type | Description |
---|---|
str
|
The encrypted password. |
Examples:
>>> from netutils.password import encrypt_cisco_type5
>>> encrypt_cisco_type5("cisco")
'$1$MHkb$v2MFmDkQX66TTxLkFF50K/'
>>>
Source code in netutils/password.py
encrypt_cisco_type7(unencrypted_password, salt=None)
¶
Given an unencrypted password of Cisco Type 7 password, encrypt it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unencrypted_password |
str
|
A password that has not been encrypted, and will be compared against. |
required |
salt |
Optional[int]
|
A random number between 0 and 15 that can be set by the operator. Defaults to random generated one. |
None
|
Returns:
Type | Description |
---|---|
str
|
The encrypted password. |
Examples:
>>> from netutils.password import encrypt_cisco_type7
>>> encrypt_cisco_type7("cisco", 11)
'110A1016141D'
>>>
Source code in netutils/password.py
encrypt_cisco_type9(unencrypted_password, salt=None)
¶
Given an unencrypted password of Cisco Type 9 password, encrypt it.
Note: This uses the built-in Python scrypt
function to generate the password
hash. However, this function is not available on the default Python installed
on MacOS. If MacOS is used, it is recommended to install Python using Homebrew
(or similar) which will include scrypt
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unencrypted_password |
str
|
A password that has not been encrypted, and will be compared against. |
required |
salt |
Optional[str]
|
a 14-character string that can be set by the operator. Defaults to random generated one. |
None
|
Returns:
Type | Description |
---|---|
str
|
The encrypted password. |
Examples:
>>> from netutils.password import encrypt_cisco_type9
>>> encrypt_cisco_type9("123456", "cvWdfQlRRDKq/U")
'$9$cvWdfQlRRDKq/U$VFTPha5VHTCbSgSUAo.nPoh50ZiXOw1zmljEjXkaq1g'
Raises:
Type | Description |
---|---|
ImportError
|
If |
Source code in netutils/password.py
encrypt_juniper_type9(unencrypted_password, salt=None)
¶
Given an unencrypted password, encrypt to Juniper $9$ type password.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unencrypted_password |
str
|
A password that has not been encrypted, and will be compared against. |
required |
salt |
Optional[int]
|
A integer that can be set by the operator. Defaults to random generated one. |
None
|
Returns:
Type | Description |
---|---|
str
|
The encrypted password. |
Examples:
>>> from netutils.password import encrypt_juniper_type9
>>> encrypt_juniper_type9("juniper", 35)
'$9$7YdwgGDkTz6oJz69A1INdb'
>>>
Source code in netutils/password.py
get_hash_salt(encrypted_password)
¶
Given an encrypted password obtain the salt value from it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
encrypted_password |
str
|
A password that has been encrypted, which the salt will be taken from. |
required |
Returns:
Type | Description |
---|---|
str
|
The encrypted password. |
Examples:
>>> from netutils.password import get_hash_salt
>>> get_hash_salt('$1$ZLGo$J.gAGxS2wqO96drs0Cith/')
'ZLGo'
>>>