fixed password hashing,

fixed plasma format
master
parent 17e4e5ae10
commit 7661f49823

@ -24,15 +24,10 @@ from random import choice
from base64 import encodebytes as _b64enc
b64encode = lambda x: _b64enc(x).rstrip()
# try:
# from smbpasswd import lmhash, nthash
# except ImportError:
# lmhash, nthash = None, None
import calculate.contrib
from passlib.hash import nthash, lmhash
from passlib.hash import nthash, lmhash, sha256_crypt, grub_pbkdf2_sha512
from .cl_print import color_print
from . import cl_overriding
from calculate.contrib.passlib.hash import sha256_crypt, grub_pbkdf2_sha512
from .cl_lang import setLocalTranslate
@ -61,7 +56,7 @@ class encrypt(color_print):
def __GenCryptSalt__(self, len=2):
"""Генерация соли для хеширования пароля (CRYPT)"""
chars = string.letters + string.digits + "./"
chars = string.ascii_letters + string.digits + "./"
salt = ""
for i in range(len):
salt = salt + choice(chars)
@ -79,21 +74,18 @@ class encrypt(color_print):
_("empty password"))
return False
if isinstance(password, str):
password = password.encode("UTF-8")
if SecHashAlg == "plain":
hash_pwd = password
elif SecHashAlg == "md5":
h = hashlib.md5(password)
hash_pwd = "{MD5}" + b64encode(h.digest())
h = hashlib.md5(password.encode("UTF-8"))
hash_pwd = "{MD5}" + b64encode(h.digest()).decode("UTF-8")
elif SecHashAlg == "smd5":
salt = os.urandom(4)
h = hashlib.md5(password)
h = hashlib.md5(password.encode("UTF-8"))
h.update(salt)
hash_pwd = "{SMD5}" + b64encode(h.digest() + salt)
hash_pwd = "{SMD5}" + b64encode(h.digest() + salt).decode("UTF-8")
elif SecHashAlg == "shadow_ssha512":
salt = self.__GenCryptSalt__(8)
@ -112,19 +104,19 @@ class encrypt(color_print):
hash_pwd = "{CRYPT}" + crypt.crypt(password, salt)
elif SecHashAlg == "sha":
h = hashlib.sha1(password)
hash_pwd = "{SHA}" + b64encode(h.digest())
h = hashlib.sha1(password.encode("UTF-8"))
hash_pwd = "{SHA}" + b64encode(h.digest()).decode("UTF-8")
elif SecHashAlg == "ssha":
salt = os.urandom(4)
h = hashlib.sha1(password)
h = hashlib.sha1(password.encode("UTF-8"))
h.update(salt)
hash_pwd = "{SSHA}" + b64encode(h.digest() + salt)
hash_pwd = "{SSHA}" + b64encode(h.digest() + salt).decode("UTF-8")
elif SecHashAlg == "lm":
hash_pwd = lmhash(password)
hash_pwd = lmhash.hash(password)
elif SecHashAlg == "nt":
hash_pwd = nthash(password)
hash_pwd = nthash.hash(password)
else:
if SecHashAlg in ("lm", "nt"):
self.printERROR(

@ -119,7 +119,7 @@ class xmlDocPlasma(xmlDoc):
return False
nameArea = ""
if firstChild(nodesNewArea[0]) is not None:
nameArea = firstChild(nodesNewArea).text.strip()
nameArea = firstChild(nodesNewArea[0]).text.strip()
flagFindArea = False
baseNodes = []
newAreaAction = None
@ -159,7 +159,7 @@ class xmlDocPlasma(xmlDoc):
oldAreaNode = oName.getparent().getparent()
oldAreaQuote = xpath.Evaluate('child::caption/quote',
oldAreaNode)[0]
if oldAreaQuote and firstChild(oldAreaQuote) is None:
if oldAreaQuote is not None and firstChild(oldAreaQuote) is None:
newAreaQuote = xpath.Evaluate('child::caption/quote',
xmlNewArea)[0]
oldAreaCaption = xpath.Evaluate('child::caption',
@ -511,7 +511,7 @@ class plasma(samba):
quotes = []
xmlQuotes = xpath.Evaluate('child::caption/quote', xmlArea)
for node in xmlQuotes:
if firstChild(node):
if firstChild(node) is not None:
quotes.append(firstChild(node).text)
if len(quotes) == 0:
quotes.append("")
@ -524,7 +524,7 @@ class plasma(samba):
for xmlArea in xmlAreas:
# Перед пустой областью и после нее удаляем переводы строк
if getQuotesArea(xmlArea) == ["", ""]:
if (xmlArea.getprevious() and
if (xmlArea.getprevious() is not None and
self.docObj.getTypeField(
xmlArea.getprevious()) == "br"):
parentNode = xmlArea.getprevious().getparent()
@ -535,12 +535,12 @@ class plasma(samba):
parentNode.remove(
xmlArea.getprevious().getprevious())
parentNode.remove(xmlArea.getprevious())
if (xmlArea.getnext() and
if (xmlArea.getnext() is not None and
self.docObj.getTypeField(
xmlArea.getnext()) == "br"):
parentNode = xmlArea.getnext().getparent()
next_next_sbl = xmlArea.getnext().getnext()
if (next_next_sbl and
if (next_next_sbl is not None and
self.docObj.getTypeField(
next_next_sbl) == "br"):
parentNode.remove(xmlArea.getnext().getnext())
@ -602,7 +602,7 @@ class plasma(samba):
for node in xmlFields:
# Добавление перевода строк в если его нет между полями
if (self.docObj.getTypeField(node) == "var" and
node.getprevious() and
node.getprevious() is not None and
not (self.docObj.getTypeField(
node.getprevious()) in ("br", "comment"))):
insertBefore(xmlArea, self.docObj.createField("br",
@ -616,7 +616,7 @@ class plasma(samba):
xmlArea.remove(xmlFields[-1])
# Если предыдущим полем не (BR или комментарий) - добавляем BR
if (xmlArea.getprevious() and
if (xmlArea.getprevious() is not None and
not (self.docObj.getTypeField(
xmlArea.getprevious()) == "br" or
self.docObj.getTypeField(
@ -626,7 +626,7 @@ class plasma(samba):
"br", [], "", [], False, False), xmlArea)
# Если есть предыдущее поле, и поле предыдущеее предыдущему
# не равно BR или комментарий то добавляем BR
if xmlArea.getprevious():
if xmlArea.getprevious() is not None:
prPrSibling = xmlArea.getprevious().getprevious()
if (prPrSibling and
not (self.docObj.getTypeField(
@ -637,9 +637,9 @@ class plasma(samba):
insertBefore(parentNode, self.docObj.createField(
"br", [], "", [], False, False), xmlArea)
# Если после есть BR а за ним ничего нет, удаляем BR
if (xmlArea.getnext() and
if (xmlArea.getnext() is not None and
self.docObj.getTypeField(xmlArea.getnext()) == "br"):
if not xmlArea.getnext().getnext():
if xmlArea.getnext().getnext() is None:
parentNode = xmlArea.getnext().getparent()
parentNode.remove(xmlArea.getnext())

Loading…
Cancel
Save