Click here to Skip to main content
15,947,057 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
ASSIGNMENT:

You should NOT use a full-featured framework, just plain code
No database, user interaction or other functionality is required (so no HTML/CSS/JavaScript); it just needs to be the code which runs and passes the tests
----------------------------------------------------------------------------------

Password Manager.
Design a program that will program that will manage passwords that meets the requirements of a
password for thesystem.
class PasswordManager
The PasswordManager class should have just 2 member variable, which will store the user name and the
encrypted password (astring).
The PasswordManager class should have the following two protected functions
encrypt(string) : takes a password (string) and returns the encrypted form of the password
verifyPassword(string): takes a string (a password) and returns true if, once encrypted, it matches the
encrypted string stored in the the member variable. Else returns false.
The PasswordManager class should have the following two public functions
validatePassword(string): this takes a string (a password) and returns true if it meets the following
criteria
- The password must not contain any whitespace
- The password must be at least 6 characters long.
- The password must contain at least one uppercase and at least one lowercase letter.
- The password must have at least one digit and symbol.
If the password does not meet these requirements,the program should display a message telling the
user why the password is invalid,specifically.It should also continue to loop until the user enter savalid
password.
setNewPassword: takes a string (a proposed password). If it meets the criteria in validatePassword, it
encrypts the password and stores it in the member variable and returns true. Otherwise returns false.
Storage
Use a file “password.txt” to store username and encrypted password. If not exist, create it at first run.
Input - Output
The main function should create and use one instance of the PasswordManagerclass.
Your program will use the following menu to prompt the user to test the implementation:

A. New User
B. Validate Password
C. Login
D. Change Password

What I have tried:

Python
from passlib.context import CryptContext
from bcrypt import hashpw, gensalt
import re 


class PasswordManager:

	plaintext_password = input("Enter your password: ")
	hashed = hashpw(plaintext_password.encode(), gensalt())
	print(hashed)

	pwd_context = CryptContext(
			schemes=["pbkdf2_sha256"],
			default="pbkdf2_sha256",
			pbkdf2_sha256__default_rounds=30000)	

	def encrypt_password(self):

		encrypt_pwd =self.pwd_context.encrypt(self.plaintext_password)
		#print(encrypt_pwd)
		return encrypt_pwd

	def verifyPassword(self,password,hashed):

		return self.pwd_context.verify(password,hashed)

 
	def validatePassword(password): 		
		while True:

			if len(password)<7:
				print("The password must be at least 6 characters long")
				break	
			elif re.search(r'[\s]',password):
				print("The password must not contain any whitespace")
				break				
			elif not re.search("[a-z]", password):
				print("The password must contain at least one lowercase")
				break
			elif not re.search("[A-Z]", password):
				print("The password must contain at least one uppercase")
				break
			elif not re.search("[0-9]", password):
				print("The password must have at least one digit")
				break
			elif not re.search("[@#$%]", password):
				print("The password must have at least one symbol in @#$%")
				break
			else:
				return True
				
	def setNewPassword(proposed_password):

		if validatePassword(proposed_password):
			pass
hong = PasswordManager()
#hong.encrypt_password()
#hong.verifyPassword('hong')
Posted
Updated 20-Apr-19 3:58am
v2
Comments
Richard MacCutchan 20-Apr-19 8:59am    
What is the problem?

1 solution

The first (implied) parameter passed to any class member function is the object reference. So your two methods should have signatures as follows:
Python
def validatePassword(self, password):

	
def setNewPassword(self, proposed_password):
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900