create(password,
salt=None,
algorithm=1,
rounds=4,
salt_len=2,
sep=u'$')
| source code
|
The meat of the module, this function takes a provided password and
generates a Unix-like passwd hash suitable for storage in portable,
text-based data files. The password is prepended with a salt (which can
also be specified explicitly, if the output needs to be repeatable) and
then hashed with the requested algorithm iterated as many times as 2
raised to the power of the rounds parameter.
The first character of the text returned by this function denotes the
separator character used to identify subsequent fields. The fields in
order are:
-
the decimal index number indicating which algorithm was used, also
mapped as convenience constants at the beginning of this module
-
the number of times (as an exponent of 2) which the algorithm was
iterated, represented by a decimal value between 0 and 16 inclusive
(0 results in one round, 16 results in 65536 rounds, and anything
higher than that is a potential resource consumption denial of
service on the application anyway)
-
the plain-text salt with which the password was prepended before
hashing
-
the resulting password hash itself, base64-encoded using . and / as
the two non-alpha-numeric characters required to reach 64
The defaults provided should be safe for everyday use, but something
more heavy-duty may be in order for admin users, such as:
create(password, algorithm=SHA256, rounds=12, salt_len=16)
|