ソースを参照

If the user enters the wrong password, print a helpful message and
re-try up to 5 times

David North 12 年 前
コミット
aca8c1b388
1 ファイル変更19 行追加5 行削除
  1. 19 5
      pwman/util/crypto.py

+ 19 - 5
pwman/util/crypto.py

@@ -224,11 +224,25 @@ class CryptoEngine:
             raise CryptoNoCallbackException("No Callback exception")
         if (self._keycrypted == None):
             raise CryptoNoKeyException("Encryption key has not been generated")
-        
-        password = self._callback.getsecret("Please enter your password")
-        tmpcipher = self._getcipher_real(password, self._algo)
-        plainkey = tmpcipher.decrypt(str(self._keycrypted).decode('base64'))
-        key = self._retrievedata(plainkey)
+
+        maxTries = 5
+        tries = 0
+
+        key = None
+
+        while tries < maxTries:
+            try:
+                password = self._callback.getsecret("Please enter your password")
+                tmpcipher = self._getcipher_real(password, self._algo)
+                plainkey = tmpcipher.decrypt(str(self._keycrypted).decode('base64'))
+                key = self._retrievedata(plainkey)
+                break
+            except CryptoBadKeyException, e:
+                print "Wrong password."
+                tries += 1
+
+        if not key:
+            raise Exception("Wrong password entered %s times; giving up" % maxTries)
         
         self._cipher = self._getcipher_real(str(key).decode('base64'), self._algo)