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