Skip to content

allanlei/flask-passlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask-Passlib

Flask extension for Passlib.

This is still WIP, but give it a try.

Installation

pip install Flask-Passlib

Usage

The default usage will attempt to figure out what version of werkzeug is being used. As of werkzeug <= 0.8.3 only supports MD5 and SHA1.

app = Flask(__name__)
passlib = Passlib(app)

To change the passlib schemes, initialize with an instance of CryptContext and set the default scheme.

from passlib.context import LaxyCryptContext
from flask.ext.passlib.context import (werkzeug_salted_md5, werkzeug_salted_sha1, 
    werkzeug_salted_sha256, werkzeug_salted_sha512)
from passlib.hash import django_pbkdf2_sha256

passlib = Passlib(app, context=LazyCryptContext(
    schemes=[
        werkzeug_salted_md5,
        werkzeug_salted_sha1,
        werkzeug_salted_sha256,
        werkzeug_salted_sha512,         

        django_pbkdf2_sha256,
    ],
    default='django_pbkdf2_sha256',
))

In this example, we have the Flask defaults with Django's PBKDF2 SHA256.

Verifying

In Flask using werkzeug's

check_password_hash(password_hash, raw_password)

With Flask-Passlib

passlib.verify(raw_password, password_hash)
Generating

In Flask using werkzeug's

generate_password_hash(raw_password, method=.., salt_length=..)

With Flask-Passlib

passlib.encrypt(raw_password, method=..., salt_length=...)

Documentation

Also check out Passlib's documentation

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published