Remember and copy passwords to clipboard using Pyperclip module in Python
It is always a difficult job to remember all our passwords for different accounts. So this is a really simple Python program which uses sys
module to obtain account name as argument from the command terminal and pyperclip
module to paste the respective account’s password to the clipboard.
Pyperclip module does not come pre-installed with Python. To install it type the below command in the terminal.
pip install pyperclip
Examples :
Command terminal Input : name_of_program.py facebook
Command terminal Output : Password : shubham456, for facebook account has been copied to the clipboard
Command terminal Input : name_of_program.py Ayushi
Command terminal Output : No such account record exists
Approach : We initialize a dictionary with keys as account names and passwords as their values. Here sys.argv
is the list of command-line arguments passed to the Python program, sys.argv[0]
is the name of the Python program and sys.argv[1]
corresponds to the first argument written by the user.
Then the program checks whether such an account (key) exists in the dictionary or not if such an account exists then it copies the password to the clipboard and displays a corresponding message. If no such account exists then the program displays a message that “No such account record exits”.
Below is the implementation of above approach :
import sys, pyperclip
def manager(account):
passwords = { "email" : "Ayushi123" ,
"facebook" : "shubham456" ,
"instagram" : "Ayushi789" ,
"geeksforgeeks" : "Ninja1"
}
if account in passwords:
pyperclip.copy(passwords[account])
print ( "Password :" , passwords[account],
", for" , account,
"account" ,
"has been copied to the clipboard" )
else :
print ( "No such account record exits" )
if __name__ = = "__main__" :
account = sys.argv[ 1 ]
manager(account)
|
Output :
Last Updated :
08 Jun, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...