From 2f10b715d303d886e3c2f1e8c168f6c774da8022 Mon Sep 17 00:00:00 2001 From: Ashish Bastola Date: Sun, 19 Nov 2023 00:30:07 -0500 Subject: [PATCH 1/3] Add: password entry verification to prevent password mistype --- keyring/cli.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/keyring/cli.py b/keyring/cli.py index 50cc4feb..1fa4908f 100644 --- a/keyring/cli.py +++ b/keyring/cli.py @@ -86,10 +86,26 @@ def do_get(self): print(password) def do_set(self): - password = self.input_password( - f"Password for '{self.username}' in '{self.service}': " - ) - set_password(self.service, self.username, password) + trials = 3 + for i in range(trials): + password = self.input_password( + f"Password for '{self.username}' in '{self.service}': ") + + reEnteredPassword = self.input_password( + f"Re-enter password for '{self.username}' in '{self.service}': ") + + if password == reEnteredPassword: + # If passwords match, set the password and break the loop + set_password(self.service, self.username, password) + break + else: + print('Password verification failed! Try again!') + + else: # This else is associated with the for-loop, not the if-statement + print(f"Password verification failed for {trials} times. Aborting!!") + sys.exit() + +# Rest of the code... def do_del(self): delete_password(self.service, self.username) From 067fda9e44cf40eab9e93f27ec3913300e739aae Mon Sep 17 00:00:00 2001 From: abastola0 Date: Sun, 19 Nov 2023 10:11:34 -0500 Subject: [PATCH 2/3] fix: non-zero exit status, PEP 8 compliant variables, removed unnecessary comments --- keyring/cli.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/keyring/cli.py b/keyring/cli.py index 1fa4908f..4346a214 100644 --- a/keyring/cli.py +++ b/keyring/cli.py @@ -91,21 +91,19 @@ def do_set(self): password = self.input_password( f"Password for '{self.username}' in '{self.service}': ") - reEnteredPassword = self.input_password( + reentered_password = self.input_password( f"Re-enter password for '{self.username}' in '{self.service}': ") - if password == reEnteredPassword: + if password == reentered_password: # If passwords match, set the password and break the loop set_password(self.service, self.username, password) break else: - print('Password verification failed! Try again!') + print('Password verification failed! Try again!\n') else: # This else is associated with the for-loop, not the if-statement - print(f"Password verification failed for {trials} times. Aborting!!") - sys.exit() - -# Rest of the code... + sys.stderr.write(f"Password verification failed for {trials} times. Aborting!!\n") + sys.exit(1) def do_del(self): delete_password(self.service, self.username) From e277eb3353a68a75dd8fae3999c9c5ff4ea8c76b Mon Sep 17 00:00:00 2001 From: abastola0 Date: Sun, 19 Nov 2023 13:34:05 -0500 Subject: [PATCH 3/3] fix: applied black code formatting --- keyring/cli.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/keyring/cli.py b/keyring/cli.py index 4346a214..c024a8bc 100644 --- a/keyring/cli.py +++ b/keyring/cli.py @@ -89,20 +89,24 @@ def do_set(self): trials = 3 for i in range(trials): password = self.input_password( - f"Password for '{self.username}' in '{self.service}': ") - + f"password for '{self.username}' in '{self.service}': " + ) + reentered_password = self.input_password( - f"Re-enter password for '{self.username}' in '{self.service}': ") - + f"re-enter password for '{self.username}' in '{self.service}': " + ) + if password == reentered_password: - # If passwords match, set the password and break the loop + # if passwords match, set the password and break the loop set_password(self.service, self.username, password) break else: - print('Password verification failed! Try again!\n') - - else: # This else is associated with the for-loop, not the if-statement - sys.stderr.write(f"Password verification failed for {trials} times. Aborting!!\n") + print('password verification failed! try again!\n') + + else: # this else is associated with the for-loop, not the if-statement + sys.stderr.write( + f"password verification failed for {trials} times. aborting!!\n" + ) sys.exit(1) def do_del(self):