mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-25 14:41:20 +00:00
Return a constant 10 character mask instead. Move ObfuscatedPasswordField into paperless/fields.py so core no longer imports it from paperless_mail, and add is_obfuscated_password() to replace the five checks
24 lines
614 B
Python
24 lines
614 B
Python
from rest_framework import serializers
|
|
|
|
OBFUSCATED_PASSWORD_MASK = "*" * 10
|
|
|
|
|
|
def is_obfuscated_password(value: str) -> bool:
|
|
"""
|
|
True if the value is only mask characters (or empty), meaning a client echoed
|
|
the placeholder back rather than supplying a new secret
|
|
"""
|
|
return value.replace("*", "") == ""
|
|
|
|
|
|
class ObfuscatedPasswordField(serializers.CharField):
|
|
"""
|
|
Sends a constant mask string instead of the password in the clear
|
|
"""
|
|
|
|
def to_representation(self, value) -> str:
|
|
return OBFUSCATED_PASSWORD_MASK
|
|
|
|
def to_internal_value(self, data):
|
|
return data
|