src/eric7/Utilities/crypto/__init__.py

branch
eric7
changeset 9971
773ad1f1ed22
parent 9653
e67609152c5e
child 10433
328f3ec4b77a
diff -r c3686b43f76b -r 773ad1f1ed22 src/eric7/Utilities/crypto/__init__.py
--- a/src/eric7/Utilities/crypto/__init__.py	Tue Apr 04 17:26:54 2023 +0200
+++ b/src/eric7/Utilities/crypto/__init__.py	Wed Apr 05 11:58:22 2023 +0200
@@ -26,7 +26,7 @@
 
 Delimiter = "$"
 
-MasterPassword = None
+MainPassword = None
 
 
 def pwEncode(pw):
@@ -54,30 +54,30 @@
     return base64.b64decode(epw[3:].encode("ascii"))[32:-32].decode("utf-8")
 
 
-def __getMasterPassword():
+def __getMainPassword():
     """
     Private module function to get the password from the user.
     """
     from .py3PBKDF2 import verifyPassword
 
-    global MasterPassword
+    global MainPassword
 
     pw, ok = QInputDialog.getText(
         None,
-        QCoreApplication.translate("Crypto", "Master Password"),
-        QCoreApplication.translate("Crypto", "Enter the master password:"),
+        QCoreApplication.translate("Crypto", "Main Password"),
+        QCoreApplication.translate("Crypto", "Enter the main password:"),
         QLineEdit.EchoMode.Password,
     )
     if ok:
-        masterPassword = Preferences.getUser("MasterPassword")
+        mainPassword = Preferences.getUser("MainPassword")
         try:
-            if masterPassword:
-                if verifyPassword(pw, masterPassword):
-                    MasterPassword = pwEncode(pw)
+            if mainPassword:
+                if verifyPassword(pw, mainPassword):
+                    MainPassword = pwEncode(pw)
                 else:
                     EricMessageBox.warning(
                         None,
-                        QCoreApplication.translate("Crypto", "Master Password"),
+                        QCoreApplication.translate("Crypto", "Main Password"),
                         QCoreApplication.translate(
                             "Crypto", """The given password is incorrect."""
                         ),
@@ -85,15 +85,15 @@
             else:
                 EricMessageBox.critical(
                     None,
-                    QCoreApplication.translate("Crypto", "Master Password"),
+                    QCoreApplication.translate("Crypto", "Main Password"),
                     QCoreApplication.translate(
-                        "Crypto", """There is no master password registered."""
+                        "Crypto", """There is no main password registered."""
                     ),
                 )
         except ValueError as why:
             EricMessageBox.warning(
                 None,
-                QCoreApplication.translate("Crypto", "Master Password"),
+                QCoreApplication.translate("Crypto", "Main Password"),
                 QCoreApplication.translate(
                     "Crypto",
                     """<p>The given password cannot be verified.</p>"""
@@ -102,27 +102,27 @@
             )
 
 
-def pwEncrypt(pw, masterPW=None):
+def pwEncrypt(pw, mainPW=None):
     """
     Module function to encrypt a password.
 
     @param pw password to encrypt (string)
-    @param masterPW password to be used for encryption (string)
+    @param mainPW password to be used for encryption (string)
     @return encrypted password (string) and flag indicating
         success (boolean)
     """
     from .py3AES import encryptData
     from .py3PBKDF2 import hashPasswordTuple
 
-    if masterPW is None:
-        if MasterPassword is None:
-            __getMasterPassword()
-            if MasterPassword is None:
+    if mainPW is None:
+        if MainPassword is None:
+            __getMainPassword()
+            if MainPassword is None:
                 return "", False
 
-        masterPW = pwDecode(MasterPassword)
+        mainPW = pwDecode(MainPassword)
 
-    digestname, iterations, salt, pwHash = hashPasswordTuple(masterPW)
+    digestname, iterations, salt, pwHash = hashPasswordTuple(mainPW)
     key = pwHash[:32]
     try:
         cipher = encryptData(key, pw.encode("utf-8"))
@@ -142,12 +142,12 @@
     )
 
 
-def pwDecrypt(epw, masterPW=None):
+def pwDecrypt(epw, mainPW=None):
     """
     Module function to decrypt a password.
 
     @param epw hashed password to decrypt (string)
-    @param masterPW password to be used for decryption (string)
+    @param mainPW password to be used for decryption (string)
     @return decrypted password (string) and flag indicating
         success (boolean)
     """
@@ -157,18 +157,18 @@
     if not epw.startswith(CryptoMarker):
         return epw, False  # it was not encoded using pwEncrypt
 
-    if masterPW is None:
-        if MasterPassword is None:
-            __getMasterPassword()
-            if MasterPassword is None:
+    if mainPW is None:
+        if MainPassword is None:
+            __getMainPassword()
+            if MainPassword is None:
                 return "", False
 
-        masterPW = pwDecode(MasterPassword)
+        mainPW = pwDecode(MainPassword)
 
     hashParameters, epw = epw[3:].rsplit(Delimiter, 1)
     try:
         # recreate the key used to encrypt
-        key = rehashPassword(masterPW, hashParameters)[:32]
+        key = rehashPassword(mainPW, hashParameters)[:32]
         plaintext = decryptData(key, base64.b64decode(epw.encode("ascii")))
     except ValueError:
         return "", False
@@ -250,14 +250,14 @@
         return plain if ok else pw
 
 
-def changeRememberedMaster(newPassword):
+def changeRememberedMain(newPassword):
     """
-    Module function to change the remembered master password.
+    Module function to change the remembered main password.
 
     @param newPassword new password to be used (string)
     """
-    global MasterPassword
-    MasterPassword = pwEncode(newPassword) if newPassword else None
+    global MainPassword
+    MainPassword = pwEncode(newPassword) if newPassword else None
 
 
 def dataEncrypt(data, password, keyLength=32, hashIterations=10000):

eric ide

mercurial