Module network_hash_gen.cisco_ios.type_5

Expand source code
from passlib.hash import md5_crypt

from network_hash_gen.base import BaseHash


class Type5(BaseHash):
    """
    Calculates the md5-crypt based type 5 hashes for Cisco IOS/IOS-XE.
    """

    salt_chars = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    salt_length = 4

    @classmethod
    def hash_salted(cls, password: str, salt: str) -> str:
        """
        Calculates a Cisco IOS/IOS-XE Type 5 hash with the given password and
        salt.

        This function assumes that the given salt is valid for that hash.
        Using an invalid salt leads to undefined behaviour.
        Prefer the `hash` and `hash_seeded` functions over this
        one if possible.
        """

        m = md5_crypt.using(salt=salt).hash(password)
        return m

Classes

class Type5

Calculates the md5-crypt based type 5 hashes for Cisco IOS/IOS-XE.

Expand source code
class Type5(BaseHash):
    """
    Calculates the md5-crypt based type 5 hashes for Cisco IOS/IOS-XE.
    """

    salt_chars = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    salt_length = 4

    @classmethod
    def hash_salted(cls, password: str, salt: str) -> str:
        """
        Calculates a Cisco IOS/IOS-XE Type 5 hash with the given password and
        salt.

        This function assumes that the given salt is valid for that hash.
        Using an invalid salt leads to undefined behaviour.
        Prefer the `hash` and `hash_seeded` functions over this
        one if possible.
        """

        m = md5_crypt.using(salt=salt).hash(password)
        return m

Ancestors

Subclasses

Class variables

var salt_chars : str

Inherited from: BaseHash.salt_chars

A string containing all characters that can be used in a salt.

var salt_length : int

Inherited from: BaseHash.salt_length

The length of the salt.

Static methods

def hash(password: str) ‑> str

Inherited from: BaseHash.hash

Calculates the hash …

def hash_salted(password: str, salt: str) ‑> str

Calculates a Cisco IOS/IOS-XE Type 5 hash with the given password and salt.

This function assumes that the given salt is valid for that hash. Using an invalid salt leads to undefined behaviour. Prefer the hash and hash_seeded functions over this one if possible.

Expand source code
@classmethod
def hash_salted(cls, password: str, salt: str) -> str:
    """
    Calculates a Cisco IOS/IOS-XE Type 5 hash with the given password and
    salt.

    This function assumes that the given salt is valid for that hash.
    Using an invalid salt leads to undefined behaviour.
    Prefer the `hash` and `hash_seeded` functions over this
    one if possible.
    """

    m = md5_crypt.using(salt=salt).hash(password)
    return m
def hash_seeded(password: str, seed: str) ‑> str

Inherited from: BaseHash.hash_seeded

Calculates a hash with the given seed used for generating a appropriate salt …