Skip to content

Replace argon2-cffi with cryptography library for password hashing#59

Merged
DavidBuchanan314 merged 1 commit intomainfrom
phc
Oct 5, 2025
Merged

Replace argon2-cffi with cryptography library for password hashing#59
DavidBuchanan314 merged 1 commit intomainfrom
phc

Conversation

@DavidBuchanan314
Copy link
Copy Markdown
Owner

Switch from argon2-cffi to cryptography's built-in Argon2id implementation to reduce dependencies. The cryptography library was already a required dependency, so this eliminates the need for an additional package.

Changes:

  • Use cryptography.hazmat.primitives.kdf.argon2.Argon2id for hashing
  • Maintain backward compatibility with existing password hashes
  • Add test case with hardcoded argon2-cffi hash to verify compatibility
  • Remove argon2-cffi from pyproject.toml dependencies

All existing password hashes continue to work, as both implementations produce and verify PHC-formatted argon2id strings.

Switch from argon2-cffi to cryptography's built-in Argon2id implementation
to reduce dependencies. The cryptography library was already a required
dependency, so this eliminates the need for an additional package.

Changes:
- Use cryptography.hazmat.primitives.kdf.argon2.Argon2id for hashing
- Maintain backward compatibility with existing password hashes
- Add test case with hardcoded argon2-cffi hash to verify compatibility
- Remove argon2-cffi from pyproject.toml dependencies

All existing password hashes continue to work, as both implementations
produce and verify PHC-formatted argon2id strings.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces argon2-cffi with the cryptography library for password hashing to reduce dependencies while maintaining backward compatibility. The change switches to cryptography's built-in Argon2id implementation since cryptography was already a required dependency.

  • Removes argon2-cffi dependency and switches to cryptography.hazmat.primitives.kdf.argon2.Argon2id
  • Maintains backward compatibility with existing password hashes through PHC format compatibility
  • Adds comprehensive test case with hardcoded argon2-cffi hash to verify compatibility

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/millipds/database.py Replaces argon2-cffi imports and methods with cryptography equivalents, adds new helper methods
tests/test_database.py Adds backward compatibility test with hardcoded argon2-cffi hash
pyproject.toml Removes argon2-cffi from dependencies

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/millipds/database.py
"""Raises ValueError if password doesn't match."""

try:
Argon2id.verify_phc_encoded(password.encode(), password_hash)
Copy link

Copilot AI Oct 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter order for Argon2id.verify_phc_encoded is incorrect. According to the cryptography library documentation, it should be Argon2id.verify_phc_encoded(password_hash, password.encode()).

Suggested change
Argon2id.verify_phc_encoded(password.encode(), password_hash)
Argon2id.verify_phc_encoded(password_hash, password.encode())

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavidBuchanan314 DavidBuchanan314 merged commit e441bde into main Oct 5, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants