from . import db

class Monkey(db.Model):
    __tablename__ = 'monkeys'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64))
    email = db.Column(db.String(64), unique=True)
    age = db.Column(db.Date())

    def __repr__(self):
        return '<User {} {}>'.format(self.id, self.email)
from . import db
from werkzeug.security import generate_password_hash, check_password_hash

class Monkey(db.Model):
    __tablename__ = 'monkeys'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64))
    email = db.Column(db.String(64), unique=True)
    password_hash = db.Column(db.String(128))
    birth_date = db.Column(db.Date())

    @property
    def password(self):
        raise AttributeError('password is not a readable attribute') 

    @password.setter
    def password(self, password):
        self.password_hash = generate_password_hash(password)

    def verify_password(self, password):
        return check_password_hash(self.password_hash, password)

    def __repr__(self):
        return '<User {} {}>'.format(self.id, self.email)
Add password hash to Monkey model
Add password hash to Monkey model

  from . import db
+ from werkzeug.security import generate_password_hash, check_password_hash
  
  class Monkey(db.Model):
      __tablename__ = 'monkeys'
  
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String(64))
      email = db.Column(db.String(64), unique=True)
+     password_hash = db.Column(db.String(128))
-     age = db.Column(db.Date())
+     birth_date = db.Column(db.Date())
+ 
+     @property
+     def password(self):
+         raise AttributeError('password is not a readable attribute') 
+ 
+     @password.setter
+     def password(self, password):
+         self.password_hash = generate_password_hash(password)
+ 
+     def verify_password(self, password):
+         return check_password_hash(self.password_hash, password)
  
      def __repr__(self):
          return '<User {} {}>'.format(self.id, self.email)
Add password hash to Monkey model
## Code Before:
from . import db

class Monkey(db.Model):
    __tablename__ = 'monkeys'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64))
    email = db.Column(db.String(64), unique=True)
    age = db.Column(db.Date())

    def __repr__(self):
        return '<User {} {}>'.format(self.id, self.email)
## Instruction:
Add password hash to Monkey model
## Code After:
from . import db
from werkzeug.security import generate_password_hash, check_password_hash

class Monkey(db.Model):
    __tablename__ = 'monkeys'

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(64))
    email = db.Column(db.String(64), unique=True)
    password_hash = db.Column(db.String(128))
    birth_date = db.Column(db.Date())

    @property
    def password(self):
        raise AttributeError('password is not a readable attribute') 

    @password.setter
    def password(self, password):
        self.password_hash = generate_password_hash(password)

    def verify_password(self, password):
        return check_password_hash(self.password_hash, password)

    def __repr__(self):
        return '<User {} {}>'.format(self.id, self.email)