blob: 3ea02951c8092b11c78cbe8a7ecdeac34ae2969f (
plain)
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
|
========================================
:mod:`passlib` - Quick Start
========================================
.. currentmodule:: passlib
Usage Example
=============
In order to get off the ground quickly, here's an
example of how to quickly encrypt and verify passwords
without having to delve too deeply into this module::
>>> from bps.security import pwhash
>>> #encrypt password using strongest algorithm defined by this module
>>> hash = pwhash.encrypt("too many secrets")
>>> hash
$6$rounds=39000$DNnCxm85LEP1WXUh$IVkALQeSuhr2hcUV90Tv8forzli3K.XwX.1JzPjgwltgvCAgllN3x1jNpG9E1C8IQPm0gEIesqATDyKh/nEnh0'
>>> #verify password against hash
>>> pwhash.verify("mypass", hash)
False
>>> pwhash.verify("too many secrets", hash)
True
>>> #identify the algorithm used in a hash
>>> pwhash.identify(hash)
'sha512-crypt'
>>> #choose a specific algorithm to use (instead of the default)
>>> hash2 = pwhash.encrypt("too many secrets", alg="bcrypt")
'$2a$11$unZuTsMEjeo5mqFX6rmRduQPBDx9t3djd2voi9W.oFhUDQu1NNMcW'
>>> #check if we used right algorithm
>>> pwhash.identify(hash2)
'bcrypt'
>>> #the hash type is autodetected by verify
>>> pwhash.verify("too many secrets", hash2)
True
Frontend Functions
==================
.. function:: encrypt
.. function:: verify
.. function:: identify
|