# Path: webtools/database.py

# 
# Path: webtools/auth/hashers.py
# def make_password(password, salt=None, hasher='default'):
#     """
#     Turn a plain-text password into a hash for database storage
# 
#     Same as encode() but generates a new random salt.  If
#     password is None or blank then UNUSABLE_PASSWORD will be
#     returned which disallows logins.
#     """
# 
#     if not password:
#         return UNUSABLE_PASSWORD
# 
#     hasher = get_hasher(hasher)
# 
#     if not salt:
#         salt = hasher.salt()
# 
#     return hasher.encode(password, salt)
# 
# def check_password(password, encoded, setter=None, preferred='default'):
#     """
#     Returns a boolean of whether the raw password matches the three
#     part encoded digest.
# 
#     If setter is specified, it'll be called when you need to
#     regenerate the password.
#     """
#     if not password or not is_password_usable(encoded):
#         return False
# 
#     preferred = get_hasher(preferred)
#     hasher = identify_hasher(encoded)
# 
#     must_update = hasher.algorithm != preferred.algorithm
#     is_correct = hasher.verify(password, encoded)
#     if setter and is_correct and must_update:
#         setter(password)
#     return is_correct


from sqlalchemy import Column
from sqlalchemy.types import Integer, String, DateTime, Unicode
from webtools.database import Base
from .hashers import make_password, check_password
# -*- coding: utf-8 -*-




class User(Base):
    __tablename__ = 'users'

    id = Column(Integer, primary_key=True, autoincrement=True)
    username = Column(Unicode(200), nullable=False, index=True)
    first_name = Column(Unicode(200), nullable=False)
    last_name = Column(Unicode(200), nullable=False)
    email = Column(Unicode(200), nullable=False)
    password = Column(String(200), nullable=False)

    def __repr__(self):
        return "<User {0}>".format(self.id)

    def set_password(self, password):
        self.password = make_password(password)

    def check_password(self, password):

# Path: webtools/database.py

# 
# Path: webtools/auth/hashers.py
# def make_password(password, salt=None, hasher='default'):
#     """
#     Turn a plain-text password into a hash for database storage
# 
#     Same as encode() but generates a new random salt.  If
#     password is None or blank then UNUSABLE_PASSWORD will be
#     returned which disallows logins.
#     """
# 
#     if not password:
#         return UNUSABLE_PASSWORD
# 
#     hasher = get_hasher(hasher)
# 
#     if not salt:
#         salt = hasher.salt()
# 
#     return hasher.encode(password, salt)
# 
# def check_password(password, encoded, setter=None, preferred='default'):
#     """
#     Returns a boolean of whether the raw password matches the three
#     part encoded digest.
# 
#     If setter is specified, it'll be called when you need to
#     regenerate the password.
#     """
#     if not password or not is_password_usable(encoded):
#         return False
# 
#     preferred = get_hasher(preferred)
#     hasher = identify_hasher(encoded)
# 
#     must_update = hasher.algorithm != preferred.algorithm
#     is_correct = hasher.verify(password, encoded)
#     if setter and is_correct and must_update:
#         setter(password)
#     return is_correct


# Path: webtools/auth/models.py
from sqlalchemy import Column
from sqlalchemy.types import Integer, String, DateTime, Unicode
from webtools.database import Base
from .hashers import make_password, check_password

# -*- coding: utf-8 -*-




class User(Base):
    __tablename__ = 'users'

    id = Column(Integer, primary_key=True, autoincrement=True)
    username = Column(Unicode(200), nullable=False, index=True)
    first_name = Column(Unicode(200), nullable=False)
    last_name = Column(Unicode(200), nullable=False)
    email = Column(Unicode(200), nullable=False)
    password = Column(String(200), nullable=False)

    def __repr__(self):
        return "<User {0}>".format(self.id)

    def set_password(self, password):
        self.password = make_password(password)

    def check_password(self, password):

        return check_password(password, self.password)