title: How to build a account validation system with flask and mongoengine
body: <p>I'm learning Flask by reading the book <a href="http://flaskbook.com/#" rel="nofollow">http://flaskbook.com/#</a> (some of the code I posted below is been taken from the examples in the book) but I want to use mongodb as database so I use the flask-mongoengine extension. Actually I'm trying to build an account validation system and you can find below my source code:</p>
  
  <pre><code>from flask.ext.mongoengine import MongoEngine
  from werkzeug.security import generate_password_hash
  from flask.ext.login import UserMixin
  
  app = Flask(__name__)
  db = MongoEngine(app)
  
  class User(UserMixin, db.Document):
      email = db.StringField(required=True, unique=True)
      username = db.StringField(required=True, unique=True, max_length=50)
      password_hash = db.StringField(max_length=128)
  
      @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)
  </code></pre>
  
  <p>and below you can see my problem in the shell:</p>
  
  <pre><code>&gt;&gt;&gt; from my_app import User
  &gt;&gt;&gt; u = User(email='example@mail.com', username='bestuser', password='ciao')
  &gt;&gt;&gt; u.password_hash
  &gt;&gt;&gt; "no output here"
  </code></pre>
  
  <p>but if I do like that:</p>
  
  <pre><code>&gt;&gt;&gt; u.password = 'ciao'
  &gt;&gt;&gt; u.password_hash
  'pbkdf2:sha1:1000$39qJ6zDT$4f2a446acc7205ad53f0b5cc5409b2d9420c29a5'
  </code></pre>
  
  <p>It works properly.</p>
  
  <p>So I don't actually know how to fix this problem. Every suggestion is very welcome.
  Thank you in advance and if you need more information just ask.</p>