Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions docs/guides/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ from device_fingerprinting import DeviceFingerprintGenerator
generator = DeviceFingerprintGenerator()

# Generate a device fingerprint
fingerprint = generator.generate_device_fingerprint()
fingerprint = generator.generate()

# The fingerprint is a unique identifier for this device
print(f"Device fingerprint: {fingerprint}")
Expand All @@ -149,9 +149,9 @@ A key property of device fingerprints is that they remain stable:

```python
# Generate fingerprint multiple times
fp1 = generator.generate_device_fingerprint()
fp2 = generator.generate_device_fingerprint()
fp3 = generator.generate_device_fingerprint()
fp1 = generator.generate()
fp2 = generator.generate()
fp3 = generator.generate()

# All should be identical
assert fp1 == fp2 == fp3
Expand Down Expand Up @@ -182,7 +182,7 @@ else:

```python
# Generate and store a fingerprint securely
fingerprint = generator.generate_device_fingerprint()
fingerprint = generator.generate()

# Store with encryption
generator.store_fingerprint("my_device", fingerprint)
Expand Down Expand Up @@ -243,7 +243,7 @@ Register a device for later verification:
```python
def register_device(user_id, device_name):
generator = DeviceFingerprintGenerator()
fingerprint = generator.generate_device_fingerprint()
fingerprint = generator.generate()

# Store with user context
storage_key = f"user_{user_id}_device_{device_name}"
Expand All @@ -262,7 +262,7 @@ Verify that a request comes from a known device:
```python
def verify_device(user_id, device_name):
generator = DeviceFingerprintGenerator()
current_fingerprint = generator.generate_device_fingerprint()
current_fingerprint = generator.generate()

# Retrieve stored fingerprint
storage_key = f"user_{user_id}_device_{device_name}"
Expand Down Expand Up @@ -315,7 +315,7 @@ Create device-bound secrets that only work on the original device:
```python
def create_bound_secret(secret_data):
generator = ProductionFingerprintGenerator()
fingerprint = generator.generate_device_fingerprint()
fingerprint = generator.generate()

# Bind secret to device
bound_token = generator.create_device_binding({
Expand All @@ -327,7 +327,7 @@ def create_bound_secret(secret_data):

def verify_bound_secret(bound_token):
generator = ProductionFingerprintGenerator()
current_fingerprint = generator.generate_device_fingerprint()
current_fingerprint = generator.generate()

# Verify on the same device
is_valid = generator.verify_device_binding(bound_token, current_fingerprint)
Expand Down
12 changes: 10 additions & 2 deletions src/device_fingerprinting/device_fingerprinting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,12 @@ def reset_device_id(storage_key: str = "device_id") -> None:
class FingerprintResult:
"""Represents the result of a fingerprint generation."""

# Equality method to compare fingerprints
def __eq__(self, other):
if not isinstance(other, FingerprintResult):
return False
return self.fingerprint == other.fingerprint

fingerprint: str
method: str
components: Dict[str, Any]
Expand Down Expand Up @@ -2323,8 +2329,10 @@ def generate(self, method: FingerprintMethod = FingerprintMethod.STABLE) -> Fing
confidence = 0.9
else:
raise ValueError(f"Unsupported fingerprint method: {method}")

fingerprint_data = json.dumps(components, sort_keys=True).encode("utf-8")
# Remove timestamp from fingerprint components to ensure consistent fingerprints generated at different times
fingerprint_components = components.copy()
fingerprint_components.pop("collected_at", None)
fingerprint_data = json.dumps(fingerprint_components, sort_keys=True).encode("utf-8")

return FingerprintResult(
fingerprint=base64.b64encode(fingerprint_data).decode("utf-8"),
Expand Down
Loading