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 form 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 :

filter_none

edit
close

play_arrow

link
brightness_4
code

import sys, pyperclip
  
# function to copy account passwords
# to clipboard
def manager(account):
     
    # dictionary in which keys are account 
    # name and values are their passwords
    passwords ={ "email" : "Ayushi123"
                "facebook" : "shubham456",
                "instagram" : "Ayushi789",
                "geeksforgeeks" : "Ninja1" 
               }
  
    if account in passwords:
          
        # copies password to clipboard
        pyperclip.copy(passwords[account])
  
        print("Password :", passwords[account],
              ", for", account,
             "account"
              "has been copied to the clipboard")
    else :
        print("No such account record exits")
          
  
# Driver function
if __name__ == "__main__":
  
    # command line argument that is name of 
    # account passed to program through cmd
    account = sys.argv[1]
  
    # calling manager function
    manager(account)
  
# This article has been contributed by
# Shubham Singh Chauhan

chevron_right


Output :
Command terminal input and output




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.