'cryptography python encryption for creating password error

I have a problem in printing the encryption in file for password using cryptography, I want to encrypt the creation of master key and the login key to decrypt and check password

from cryptography.fernet import Fernet

class hash_password():
    def genewrite_key():
        key= Fernet.generate_key()
        with open("pass.key","wb") as key_file:
            key_file.write(key)

    def get_key():
        key= open("pass.key","rb").read()
        return key


class signIn():
    def create_masterkey(hash):
        hash_password.genewrite_key()
        cr_pass = input("Create your password so you can access your data in future and please remember it: ")
        hash = cr_pass.encode()
        key= hash_password.get_key()
        a= Fernet(key)
        txt = a.encrypt(hash)

        with open('P1ssW0rd.txt', 'a') as f:
            f.write(str(hash) +"\n")     
        if len(cr_pass)<= 6:
            print("Password is too short")
            signIn().create_masterkey()
        else: print("Passcode Created Successfully!")

    def Login():
        
        hash_password.genewrite_key() 
        key= hash_password.get_key()
        a= Fernet(key)
        login_pass = input("whats you passcode? ")
        file = open("P1ssW0rd.txt")
        decoded_text = a.decrypt(hash)

        if(login_pass in file.read()):
            print("true password")
        else:
            print("Creditionals doesn't exist")
            signIn().create_masterkey()
        file.close()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source