api.auth.user: improve password hashing
This commit is contained in:
parent
b6e6f1c833
commit
1709290ea9
4 changed files with 10 additions and 8 deletions
|
|
@ -25,6 +25,10 @@ class User(BaseModel):
|
||||||
class UserIn(User):
|
class UserIn(User):
|
||||||
password: str | None = None
|
password: str | None = None
|
||||||
|
|
||||||
|
def hashPassword(self) -> str | None:
|
||||||
|
pw = self.password
|
||||||
|
return pw and hashPassword(pw) or None
|
||||||
|
|
||||||
# password handling, authentication
|
# password handling, authentication
|
||||||
|
|
||||||
pw_hash = PasswordHash.recommended()
|
pw_hash = PasswordHash.recommended()
|
||||||
|
|
|
||||||
|
|
@ -56,13 +56,13 @@ class Record:
|
||||||
return cls(**self.asDict(flatten=True))
|
return cls(**self.asDict(flatten=True))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def prepareData(data):
|
def prepareData(data, obj):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fromObject(cls, obj):
|
def fromObject(cls, obj):
|
||||||
inp = obj.model_dump()
|
inp = obj.model_dump()
|
||||||
headValues = [inp.pop(hf) for hf in cls.headFields]
|
headValues = [inp.pop(hf) for hf in cls.headFields]
|
||||||
data = cls.prepareData(inp)
|
data = cls.prepareData(inp, obj)
|
||||||
return cls(*headValues, data=data)
|
return cls(*headValues, data=data)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ class Record(shape.Record):
|
||||||
return base | super().asDict()
|
return base | super().asDict()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def prepareData(data):
|
def prepareData(data, obj):
|
||||||
data.pop('uid', None)
|
data.pop('uid', None)
|
||||||
data.pop('timeStamp', None)
|
data.pop('timeStamp', None)
|
||||||
return data
|
return data
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,10 @@ class User(concept.Concept):
|
||||||
prefix = 'user'
|
prefix = 'user'
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def prepareData(data):
|
def prepareData(data, obj):
|
||||||
from scopes.api.auth.user import hashPassword
|
data = concept.Concept.prepareData(data, obj)
|
||||||
data = concept.Concept.prepareData(data)
|
|
||||||
pw = data.pop('password', None)
|
pw = data.pop('password', None)
|
||||||
if pw:
|
data['pw_hash'] = obj.hashPassword()
|
||||||
data['pw_hash'] = hashPassword(pw)
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue