since the code for encrypting password is required in both __init__ and check_ passwordwe pull it out to its own method this wayit only needs to be changed in one place if someone realizes it is insecure and needs improvement this class could easily be extended to include mandatory or optional personal detailssuch as namescontact informationand birth dates before we write code to add users (which will happen in the as-yet undefined authenticator class)we should examine some use cases if all goes wellwe can add user with username and passwordthe user object is created and inserted into dictionary but in what ways can all not go wellwellclearly we don' want to add user with username that already exists in the dictionary if we did sowe' overwrite an existing user' data and the new user might have access to that user' privileges sowe'll need usernamealreadyexists exception alsofor security' sakewe should probably raise an exception if the password is too short both of these exceptions will extend authexceptionwhich we mentioned earlier sobefore writing the authenticator classlet' define these three exception classesclass authexception(exception)def __init__(selfusernameuser=none)super(__init__(usernameuserself username username self user user class usernamealreadyexists(authexception)pass class passwordtooshort(authexception)pass the authexception requires username and has an optional user parameter this second parameter should be an instance of the user class associated with that username the two specific exceptions we're defining simply need to inform the calling class of an exceptional circumstanceso we don' need to add any extra methods to them now let' start on the authenticator class it can simply be mapping of usernames to user objectsso we'll start with dictionary in the initialization function the method for adding user needs to check the two conditions (password length and previously existing usersbefore creating new user instance and adding it to the dictionaryclass authenticatordef __init__(self)'''construct an authenticator to manage