summaryrefslogtreecommitdiff
path: root/docs/lib/passlib.hash.hex_digests.rst
blob: de13bca181d96b7c9fd0b9f35cb216c7cdfb18fe (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
==============================================================
:samp:`passlib.hash.hex_{digest}` - Generic Hexdecimal Digests
==============================================================

.. warning::

    Using a single round of any cryptographic hash
    (especially without a salt) is so insecure
    that it's barely better than plaintext.
    Do not use these schemes in new applications.

.. currentmodule:: passlib.hash

Some existing applications store passwords by storing them using
hexidecimal-encoded message digests, such as MD5 or SHA1.
Such schemes are *extremely* vulnerable to pre-computed brute-force attacks,
and should not be used in new applications. However, for the sake
of backwards compatibility when converting existing applications,
Passlib provides wrappers for few of the common hashes.
These classes all wrap the underlying hashlib implementations,
and can be used directly as follows::

    >>> from passlib.hash import hex_sha1 as hex_sha1

    >>> # encrypt password
    >>> h = hex_sha1.encrypt("password")
    >>> h
    '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'

    >>> # verify correct password
    >>> hex_sha1.verify("password", h)
    True
    
    >>> # verify incorrect password
    >>> hex_sha1.verify("secret", h)
    False

.. seealso:: the generic :ref:`PasswordHash usage examples <password-hash-examples>`

.. index:: virtualbox; passwordhash

Interface
=========
.. class:: hex_md4()
.. class:: hex_md5()
.. class:: hex_sha1()
.. class:: hex_sha256()
.. class:: hex_sha512()

    Each of these classes implements a plain hexidecimal encoded
    message digest, using the relevant digest function from :mod:`!hashlib`,
    and following the :ref:`password-hash-api`.

    They support no settings or other keywords.

.. note::

   Oracle VirtualBox's :cmd:`VBoxManager internalcommands passwordhash` command
   uses :class:`hex_sha256`.

Format & Algorithm
==================
All of these classes just report the result of the specified digest,
encoded as a series of lowercase hexidecimal characters;
though upper case is accepted as input.