anomaly / anomaly/lab-python-server

Building Custom Comparator for SQLAlchemy for the password property

Đang mở
#51 2 bình luận 0 reaction 1 người được giao Được @devraj nhận Xem trên GitHub
Ngôn ngữ chính
Python
Star
16
Fork
4
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Extending from the pattern that allows developers to simply set the `password` property and a setter hashes it on the way in. The `User` model class has substantial documentation on this. The general approach is to declare the property as:

```python
_password = Column("password",
String,
nullable=True)
```

followed by exposing the `password` property as:

```python
@property
def password(self):
return self._password
```

and finally overriding the setter to `hash` the password on the way in:
```python
@password.setter
def password(self, password):
self._password = hash_password(password)
```

The [Building Custom Comparator](https://docs.sqlalchemy.org/en/14/orm/extensions/hybrid.html#building-custom-comparators) guide outlines how we can override the comparator of `hybrid_property` in `SQLAlchemy`, if we adopt this paradigm then we can achieve comparing password as:

```python
user.password == password
```

as opposed using `check_password` method

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.