Open In App

Remember and copy passwords to clipboard using Pyperclip module in Python

Improve
Improve
Like Article
Like
Save
Share
Report

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
  
# 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


Output :
Command terminal input and output



Last Updated : 08 Jun, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads