Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Bummer! cannot import name 'HASHER'

I'm having trouble with this and kinda confused plus I keep getting the error

Bummer! cannot import name 'HASHER' import datetime

from peewee import * import hashlib

DATABASE = SqliteDatabase('recipes.db')

class User(Model): username = CharField(unique=True) password = CharField()

class Meta:
    database = DATABASE

@classmethod
def create_user(cls, username, password):
    try:
        cls.get(cls.username**username)
    except cls.DoesNotExist:
        user = cls(username=username)
        password = 'pa$$w0rd'
        h = hashlib.md5(password.encode)
        user.save()
        return user
    else:
        raise Exception("User already exists")        

class Recipe(Model): name = CharField() created_at = DateTimeField(default=datetime.datetime.now)

class Meta:
    database = DATABASE

class Ingredient(Model): name = CharField() description = CharField() quantity = DecimalField() measurement_type = CharField() recipe = ForeignKeyField(Recipe)

class Meta:
    database = DATABASE

def initialize(): DATABASE.connect() DATABASE.create_tables([User, Recipe, Ingredient], safe=True) DATABASE.close()

import datetime

from peewee import * import hashlib

DATABASE = SqliteDatabase('recipes.db')

class User(Model): username = CharField(unique=True) password = CharField()

class Meta:
    database = DATABASE

@classmethod
def create_user(cls, username, password):
    try:
        cls.get(cls.username**username)
    except cls.DoesNotExist:
        user = cls(username=username)
        password = 'pa$$w0rd'
        h = hashlib.md5(password.encode)
        user.save()
        return user
    else:
        raise Exception("User already exists")        

class Recipe(Model): name = CharField() created_at = DateTimeField(default=datetime.datetime.now)

class Meta:
    database = DATABASE

class Ingredient(Model): name = CharField() description = CharField() quantity = DecimalField() measurement_type = CharField() recipe = ForeignKeyField(Recipe)

class Meta:
    database = DATABASE

def initialize(): DATABASE.connect() DATABASE.create_tables([User, Recipe, Ingredient], safe=True) DATABASE.close()

3 Answers

@staticmethod def hash_password(password): return HASHER.hash(password)

Should pass the 2nd part watch you indentation. Also if you go a video ahead and load the workspace alot of times theres pretty much an example of the code they ask you to write; get use to lookin at the documentation on the web to. But yeah bangin my head on the desk alot with these.

GoodLuck.

thanks it worked

import datetime

from argon2 import PasswordHasher from peewee import *

HASHER = PasswordHasher() DATABASE = SqliteDatabase('recipes.db')

worked for me

thanks!

@Jeff Bender Hey man check this code out and let me know what I am doing wrong it tells me that I need to name it user.hash_password but not sure where I need to put the name I had tried in both of the classes and now it tells me no longer passing and its the second part of the first question you helped me on

@classmethod def create_user(cls, username, password): try: cls.get(cls.username**username) except cls.DoesNotExist: user = cls(username=username) user= cls(user.hash_password) user.save() return user else: raise Exception("User already exists")

@staticmethod
def set_password(password):
    return HASHER.hash(password)
def verify_password(user, password)
    return HASHER.verify(user.password, password)

@classmethod def create_user(cls, username, password): try: cls.get(cls.username**username) except cls.DoesNotExist: user = cls(username=username) user= cls(user.hash_password) user.save() return user else: raise Exception("User already exists")

@staticmethod
def set_password(password):
    return HASHER.hash(password)
def verify_password(user, password)
    return HASHER.verify(user.password, password)