diff --git a/vertica_python/vertica/messages/frontend_messages/password.py b/vertica_python/vertica/messages/frontend_messages/password.py index f48d2684..78041fdc 100644 --- a/vertica_python/vertica/messages/frontend_messages/password.py +++ b/vertica_python/vertica/messages/frontend_messages/password.py @@ -42,9 +42,41 @@ from ..backend_messages.authentication import Authentication from ....compat import as_bytes -from . import crypt_windows as crypt - +try: + if os.name == 'nt': + # Windows-specific crypt module workaround + # Try using passlib or cryptography in place of 'crypt' on Windows + try: + from passlib.hash import sha256_crypt as crypt # Passlib as fallback + except ImportError: + try: + from cryptography.hazmat.primitives import hashes # Cryptography fallback + crypt = hashes # Note: hashes doesn't replace 'crypt', review usage + except ImportError: + raise ValueError( + "Neither 'passlib' nor 'cryptography' is available on Windows, " + "and the 'crypt' module is missing. " + "Please install one of these libraries or adapt the code to use a different hashing mechanism." + ) + else: + # Try importing cryptography as an alternative for non-Windows platforms + try: + from cryptography.hazmat.primitives import hashes + crypt = hashes # Note: hashes doesn't replace 'crypt', review usage + except ImportError: + # If cryptography isn't available, fallback to passlib + try: + from passlib.hash import sha256_crypt as crypt + except ImportError: + raise ValueError( + "Neither 'cryptography' nor 'passlib' is available, " + "and the 'crypt' module is missing. " + "Please install one of these libraries or adapt the code to use a different hashing mechanism." + ) +except ValueError as e: + raise ValueError(f"Error importing crypt module: {e}") from e + class Password(BulkFrontendMessage): message_id = b'p'