Skip to content

crypt Module

⚠️ REMOVED IN PYTHON 3.13: The crypt module was deprecated in Python 3.11 and removed in Python 3.13.

The crypt module provides Unix password hashing functionality using the crypt() system call (Unix/Linux only).

Complexity Reference

Operation Time Space Notes
crypt() O(n) O(1) n = work factor/iterations; intentionally slow
Hash password O(n) O(n) Compute hash

Password Hashing

Hashing Passwords

import crypt

# Hash password - O(n)
password = "mypassword"
hashed = crypt.crypt(password, salt=crypt.METHOD_SHA512)

print(hashed)  # Hashed format

# Verify by re-hashing
if crypt.crypt(password, hashed) == hashed:
    print("Password correct")