Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Remember and copy passwords to clipboard using Pyperclip module in Python

  • Difficulty Level : Basic
  • Last Updated : 19 Feb, 2020

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 : facebook
Command terminal Output : Password : shubham456, for facebook account has been copied to the clipboard

Command terminal Input : 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
        print("Password :", passwords[account],
              ", for", 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
# This article has been contributed by
# Shubham Singh Chauhan

Output :
Command terminal input and output

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!