Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2....
File: crypt.py
"""Wrapper to the POSIX crypt library call and associated functionality.
[0] Fix | Delete
[1] Fix | Delete
Note that the ``methods`` and ``METHOD_*`` attributes are non-standard
[2] Fix | Delete
extensions to Python 2.7, backported from 3.3"""
[3] Fix | Delete
[4] Fix | Delete
import _crypt
[5] Fix | Delete
import string as _string
[6] Fix | Delete
from random import SystemRandom as _SystemRandom
[7] Fix | Delete
from collections import namedtuple as _namedtuple
[8] Fix | Delete
[9] Fix | Delete
[10] Fix | Delete
_saltchars = _string.ascii_letters + _string.digits + './'
[11] Fix | Delete
_sr = _SystemRandom()
[12] Fix | Delete
[13] Fix | Delete
[14] Fix | Delete
class _Method(_namedtuple('_Method', 'name ident salt_chars total_size')):
[15] Fix | Delete
[16] Fix | Delete
"""Class representing a salt method per the Modular Crypt Format or the
[17] Fix | Delete
legacy 2-character crypt method."""
[18] Fix | Delete
[19] Fix | Delete
def __repr__(self):
[20] Fix | Delete
return '<crypt.METHOD_%s>' % self.name
[21] Fix | Delete
[22] Fix | Delete
[23] Fix | Delete
def mksalt(method=None):
[24] Fix | Delete
"""Generate a salt for the specified method.
[25] Fix | Delete
[26] Fix | Delete
If not specified, the strongest available method will be used.
[27] Fix | Delete
[28] Fix | Delete
This is a non-standard extension to Python 2.7, backported from 3.3
[29] Fix | Delete
"""
[30] Fix | Delete
if method is None:
[31] Fix | Delete
method = methods[0]
[32] Fix | Delete
s = '$%s$' % method.ident if method.ident else ''
[33] Fix | Delete
s += ''.join(_sr.sample(_saltchars, method.salt_chars))
[34] Fix | Delete
return s
[35] Fix | Delete
[36] Fix | Delete
[37] Fix | Delete
def crypt(word, salt=None):
[38] Fix | Delete
"""Return a string representing the one-way hash of a password, with a salt
[39] Fix | Delete
prepended.
[40] Fix | Delete
[41] Fix | Delete
If ``salt`` is not specified or is ``None``, the strongest
[42] Fix | Delete
available method will be selected and a salt generated. Otherwise,
[43] Fix | Delete
``salt`` may be one of the ``crypt.METHOD_*`` values, or a string as
[44] Fix | Delete
returned by ``crypt.mksalt()``.
[45] Fix | Delete
[46] Fix | Delete
Note that these are non-standard extensions to Python 2.7's crypt.crypt()
[47] Fix | Delete
entrypoint, backported from 3.3: the standard Python 2.7 crypt.crypt()
[48] Fix | Delete
entrypoint requires two strings as the parameters, and does not support
[49] Fix | Delete
keyword arguments.
[50] Fix | Delete
"""
[51] Fix | Delete
if salt is None or isinstance(salt, _Method):
[52] Fix | Delete
salt = mksalt(salt)
[53] Fix | Delete
return _crypt.crypt(word, salt)
[54] Fix | Delete
[55] Fix | Delete
[56] Fix | Delete
# available salting/crypto methods
[57] Fix | Delete
METHOD_CRYPT = _Method('CRYPT', None, 2, 13)
[58] Fix | Delete
METHOD_MD5 = _Method('MD5', '1', 8, 34)
[59] Fix | Delete
METHOD_SHA256 = _Method('SHA256', '5', 16, 63)
[60] Fix | Delete
METHOD_SHA512 = _Method('SHA512', '6', 16, 106)
[61] Fix | Delete
[62] Fix | Delete
methods = []
[63] Fix | Delete
for _method in (METHOD_SHA512, METHOD_SHA256, METHOD_MD5):
[64] Fix | Delete
_result = crypt('', _method)
[65] Fix | Delete
if _result and len(_result) == _method.total_size:
[66] Fix | Delete
methods.append(_method)
[67] Fix | Delete
methods.append(METHOD_CRYPT)
[68] Fix | Delete
del _result, _method
[69] Fix | Delete
[70] Fix | Delete
[71] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function