kvesteri/sqlalchemy-utils — pull request #24 by mehcode (2013-07-10 08:12:12+00:00)
Title: Add password type decorator

Implemented the Password Type from #12

```python
from sqlalchemy_util import Password, PasswordType
import sqlalchemy as sa

class User(Base):
# [...]

# kwargs are passed directly to a new CryptContext
password = sa.Column(PasswordType(
schemes=[
'pbkdf2_sha512',
'md5_crypt'
],

deprecated=['md5_crypt']))

>>> u = User()
>>> u.password = 'b'
>>> u.password.raw
b'$pbkdf2-sha512$.....'

>>> u.password == 'b'
True

# The raw hash can be set as follows.
>>> u.password = Password('!')
>>> u.password.raw = '!'

# Passwords are auto-updated from deprecated hashes
>>> from passlib.hash import md5_crypt
>>> u.password = Password(md5_crypt.encrypt('b'))
>>> u.password.raw
b'$1$...'

>>> u.password == 'b'
True

>>> u.password.raw
b'$pbkdf2-sha512$.....'
```