Question

In: Computer Science

PYTHON Exercise 3. Password locker. 1. You probably have accounts on many different websites. It’s a...

PYTHON Exercise 3. Password locker. 1. You probably have accounts on many different websites. It’s a bad habit to use the same password for each of them because if any of those sites has a security breach, the hackers will learn the password to all of your other accounts. Develop a simple password manager software on your computer where you write the account name (blog, facebook, instagram, etc) as an argument and the password is copied to the clipboard. Then you can paste it into the website’s Password field. For example, if you execute this command line in your terminal: python3 ./pw.py instagram The password for Instagram (example: htS:D`t*hQH3]9"C) should be copied to the clipboard. 2. Add a second argument where is a master password. Only copy to the clipboard the password for the first argument if the master password is correct. (Note: (You don’t need to code this) Now your program is more secure than before, but it is still insecure because anyone could go to your source file and get the passwords. To be secure: - You should introduce your passwords through the command line arguments. - Once a password is introduced, encrypt them using a master password you only know (not in the source file, passed through the command line arguments) and store them in a file. - When you want to retrieve them, decrypt them using the master password. Then, it would be secure because no one can retrieve the passwords without the master password and the passwords are saved encrypted in the computer.)

Solutions

Expert Solution

Q1. Python code(Commented)

'''
Execute this script as follows:
>> python file_name.py website_name
'''
import pyperclip # library to copy password to clip board
import sys # library to read commandline argument

# dummy password dictionary
psswd_dict = {
   'website1':12345,
   'website2' :58946,
   'website3' :48955,
   'website4' :78493
}

# read the website to be used from commandline
choice = sys.argv[1]
password = psswd_dict[choice]

# copy the password to the clipboard
pyperclip.copy(str(password))
spam = pyperclip.paste()

#end of the program

Q2. Python code for password manager with master password

Script 1(To encrypt passwords of the websites)[To be used only once to encrypt the website passwords]

import base64
import os
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.fernet import Fernet

# dummy password dictionary
psswd_dict = {
   'web1':1234,
   'web2':5677,
   'web3':7896
}
psswd_list = ['web1','web2','web3']

# file to store the encrypted keys
file = open('key.key','wb')

# master password used for encryption
MASTER_PASSWORD = "Howdy"
password = MASTER_PASSWORD.encode()

# salt is cryptographically strong random number
salt = '\xc2h\xf9\xd3\xa9\xd4\xf0\x05V\x10`\rOE\xa9\xb1'
kdf = PBKDF2HMAC(
   algorithm = hashes.SHA256(),
   length = 32,
   salt = salt,
   iterations = 100000,
   backend = default_backend())
# generate the hashed for the MASTER_PASSWORD
key = base64.urlsafe_b64encode(kdf.derive(password))

#encrypt the passwords and save it to a file
f = Fernet(key)
for website in psswd_list:
   encoded = str(psswd_dict[website])
   encrypted = f.encrypt(encoded.encode())
   file.write(encrypted)
   file.write("\n")

Script 2(password manager program):

'''
Execute this script as follows:
>> python file_name.py website_name master_password
'''
import base64
import os
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.fernet import Fernet

import pyperclip # library to copy password to clip board
import sys # library to read commandline argument
import bcrypt # library to use bcrypt hash function

MASTER_PASSWORD = "Howdy"

# open the file to read the encrypted website keys
file = open('key.key','rb')

psswd_list = ['web1','web2','web3']

# list containing the encrypted password
file_list = file.readlines()

# read the website to be used from commandline
choice = sys.argv[1]

# same salt as before
salt = '\xc2h\xf9\xd3\xa9\xd4\xf0\x05V\x10`\rOE\xa9\xb1'
kdf = PBKDF2HMAC(
   algorithm = hashes.SHA256(),
   length = 32,
   salt = salt,
   iterations = 100000,
   backend = default_backend())

# read the master password
master_psswd = sys.argv[2]
password = master_psswd.encode()

if master_psswd==MASTER_PASSWORD:
   # decrypt message
   key = base64.urlsafe_b64encode(kdf.derive(password)) # generate key from master password
   f2 = Fernet(key)
   encrypted = file_list[psswd_list.index(choice)]
   # remove the /n
   encrypted = encrypted[:-1]
   decrypted = f2.decrypt(encrypted) # decrypt using the key
   original_msg = decrypted.decode()
  
   #copy to clip board
   pyperclip.copy(str(original_msg))
   spam = pyperclip.paste()  

else:
   print("master password incorrect")  



Related Solutions

I have to write a random password generator in Python 3 and im having some trouble...
I have to write a random password generator in Python 3 and im having some trouble writing the code and i dont really know where to start. The prompt goes as such: The problem in this assignment is to write a Python program that uses functions to build (several options of) passwords for the user. More specifically, your program will do the following: 1. Prompt the user for the length of the password to be generated. Call this length lenP....
Many of you are biology majors, and the rest of you have probably taken a biology...
Many of you are biology majors, and the rest of you have probably taken a biology class, so this week's discussion question is this: How much of Linnaeus' classification system survives today? Which part do you still learn in your classes? What, if anything, has changed in classification systems since Linnaeus' time?
PLEASE ANSWER WASNT ANSWERED PYTHON You will ask 3 questions USERNAME = "user1" PASSWORD = "password1"...
PLEASE ANSWER WASNT ANSWERED PYTHON You will ask 3 questions USERNAME = "user1" PASSWORD = "password1" What is your user name? What is your password? What is your age? If the user name and password are incorrect, display a message that says - Your credentials are not valid If both user name and password are correct, ask question 3 If the answer to question 3 is eighteen and greater, display a message that says - You're considered an adult If...
You are required to use at least 3 different ACADEMICALLY credible articles/books/websites as references. You can...
You are required to use at least 3 different ACADEMICALLY credible articles/books/websites as references. You can use whatever search method you like but make sure your information is credible AND published within the last 5 years. The paper should be 3 full pages, no plagiarism The following needs to be covered in the paper: 1. Describe the heart disease. 2. What happens to the person who has the heart disease? 3.How it is diagnosed 4. How it is treated 5.How...
You are required to use at least 3 different ACADEMICALLY credible articles/books/websites as references. You can...
You are required to use at least 3 different ACADEMICALLY credible articles/books/websites as references. You can use whatever search method you like but make sure your information is credible AND published within the last 5 years. The paper should be 3 full pages, The following needs to be covered in the paper: 1. Describe the heart disease. 2. What happens to the person who has the heart disease? 3.How it is diagnosed 4. How it is treated 5.How it can...
Hundreds of different dog breeds have been recognized, and you have probably already identified your very...
Hundreds of different dog breeds have been recognized, and you have probably already identified your very favorite breed! Historically, dog breeds have been traditionally grouped together as one species. However, there is an ongoing debate about what actually defines a "species." This week, you have learned about several different species concepts (each defining the term "species" based on different criteria.) Refer to the Morphological Species Concept, the Biological Species Concept, and the Phylogenetic Species Concept in your discussion about whether...
Question3: Consider you have the following data for some user accounts: [6 marks] Username Password User1...
Question3: Consider you have the following data for some user accounts: [6 marks] Username Password User1 101010 User2 112121 User3 211211 User4 312132 1. Write a function called validate which takes 2 arguments: a dictionary, a username, and a password. The function should do the following: [3 marks] Find the given username in the dictionary and compare the given password with the one that belongs to that username in the dictionary. Return true if password is correct and false if...
After you have completed the Unit 1 material and have considered the many different definitions of...
After you have completed the Unit 1 material and have considered the many different definitions of Pop Culture posed within the unit, consider the differences between high culture and popular culture. Answer the following questions: When someone is said to be “cultured”, does this refer to high culture, popular culture, or both? How would you define, in your own words, “high culture” and “popular culture”? What characteristics of high culture are also present in popular culture? What makes something “high”...
You have probably had the experience of being screened many times (e.g., cholesterol test, glucose level...
You have probably had the experience of being screened many times (e.g., cholesterol test, glucose level test, blood pressure measurement). What is more important information from a PATIENT’s point of view (PPV/NPV vs. Sensitivity/Specificity), and what is more important information from a PHYSICIAN’s point of view (PPV/NPV vs. Sensitivity/Specificity)?
1. Explain how it is possible for you to have so many different kinds of cells...
1. Explain how it is possible for you to have so many different kinds of cells in your body (e.g. muscle cells, skin cells, liver cells, etc.) when nearly all of the cells contain the same 46 molecules of DNA (chromosomes). 2. Explain in your own words your understanding of the central dogma of biology. Answer each of the following questions. What is the primary structure of a protein? Of what importance is the primary structure of a protein? What...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT