Skip to content

Instantly share code, notes, and snippets.

@ovidiucs
Created May 18, 2015 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ovidiucs/25bf34ff626f727a6499 to your computer and use it in GitHub Desktop.
Save ovidiucs/25bf34ff626f727a6499 to your computer and use it in GitHub Desktop.
class
class User(UserMixin, db.Model):
__tablename__ = 'users'
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(16), index=True, unique=True)
username = db.Column(db.String(16), index=True, unique=True)
password_hash = db.Column(db.String(64))
def set_password(self, password):
self.password_hash = generate_password_hash(password)
def verify_password(self, password):
return check_password_hash(self.password_hash, password)
@staticmethod
def register(username, password):
user = User(username=username)
user.set_password(password)
db.session.add(user)
db.session.commit()
return user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment