Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
version 20200709.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Jul 10, 2020
1 parent d799062 commit 61c14cb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pydal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "20200630.1"
__version__ = "20200709.1"

from .base import DAL
from .objects import Field
Expand Down
7 changes: 5 additions & 2 deletions pydal/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ def insert(self, **fields):
return ret

def _validate_fields(self, fields, defattr="default", id=None):
from .validators import CRYPT
response = Row()
response.id, response.errors, new_fields = None, Row(), Row()
for field in self:
Expand All @@ -905,10 +906,12 @@ def _validate_fields(self, fields, defattr="default", id=None):
if callable(default):
default = default()
if not field.compute:
value = fields.get(field.name, default)
value, error = field.validate(value, id)
ovalue = fields.get(field.name, default)
value, error = field.validate(ovalue, id)
if error:
response.errors[field.name] = "%s" % error
elif field.type == 'password' and ovalue == CRYPT.STARS:
pass
elif field.name in fields:
# only write if the field was passed and no error
new_fields[field.name] = value
Expand Down
6 changes: 6 additions & 0 deletions pydal/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4420,6 +4420,8 @@ class CRYPT(Validator):
True
"""

STARS = '******'

def __init__(
self,
key=None,
Expand All @@ -4444,13 +4446,17 @@ def __init__(
self.salt = salt

def validate(self, value, record_id=None):
if value == self.STARS:
return None
v = value and str(value)[: self.max_length]
if not v or len(v) < self.min_length:
raise ValidationError(self.translator(self.error_message))
if isinstance(value, LazyCrypt):
return value
return LazyCrypt(self, value)

def formatter(self, value):
return self.STARS

# entropy calculator for IS_STRONG
#
Expand Down

0 comments on commit 61c14cb

Please sign in to comment.