File: index.rst

package info (click to toggle)
flask-bcrypt 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 172 kB
  • sloc: python: 294; makefile: 113; sh: 17
file content (68 lines) | stat: -rw-r--r-- 2,036 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Flask-Bcrypt
=============

.. module:: flask_bcrypt

Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for
your application.

Due to the recent increased prevalence of powerful hardware, such as modern
GPUs, hashes have become increasingly easy to crack. A proactive solution to
this is to use a hash that was designed to be "de-optimized". Bcrypt is such
a hashing facility; unlike hashing algorithms such as MD5 and SHA1, which are
optimized for speed, bcrypt is intentionally structured to be slow.

For sensitive data that must be protected, such as passwords, bcrypt is an
advisable choice.

.. _Flask-Bcrypt: http://github.com/maxcountryman/flask-bcrypt
.. _Flask: http://flask.pocoo.org/

Installation
------------

Install the extension with one of the following commands:

    $ easy_install flask-bcrypt

or alternatively if you have pip installed:
    
    $ pip install flask-bcrypt

.. note::
    You need Python Development Headers to install py-bcrypt package, needed
    as a dependency. If you are on Mac OS or Windows, you probably have it
    already installed. Otherwise look for python-dev package for Debian-based
    distributives and for python-devel package for RedHat-based.

Usage
-----

To use the extension simply import the class wrapper and pass the Flask app
object back to here. Do so like this::
    
    from flask import Flask
    from flask_bcrypt import Bcrypt
    
    app = Flask(__name__)
    bcrypt = Bcrypt(app)

Two primary hashing methods are now exposed by way of the bcrypt object. In Python 2, use
them like so::

    pw_hash = bcrypt.generate_password_hash('hunter2')
    bcrypt.check_password_hash(pw_hash, 'hunter2') # returns True
    
In Python 3, you need to use decode('utf-8') on generate_password_hash(), like below:

    pw_hash = bcrypt.generate_password_hash('hunter2').decode('utf-8')

API
___
.. autoclass:: flask_bcrypt.Bcrypt
    :members:

.. autofunction:: flask_bcrypt.generate_password_hash

.. autofunction:: flask_bcrypt.check_password_hash