# Path: pyledger/server/config.py
# SECRET = b'test'
# LIFETIME = 1
# 
# Path: pyledger/server/config.py
# SECRET = b'test'
# LIFETIME = 1


import base64
from enum import Enum
from cryptography.exceptions import InvalidKey
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, \
    LargeBinary
from sqlalchemy import create_engine, desc
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy.orm import sessionmaker, scoped_session
from pyledger.server.config import args
from pyledger.server.config import password_backend, SECRET
class User(Model):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    name = Column(String, unique=True)
    when = Column(DateTime)
    info = Column(LargeBinary)
    key = Column(String)
    password = Column(String)
    profile = Column(Integer)
    contracts = relationship("Contract", back_populates="user")
    sessions = relationship("Session", back_populates='user')

    def __repr__(self):
        return '<User {} with key: {}>'.format(self.name, self.key)

    def __str__(self):
        return '<User {} with key: {}>'.format(self.name, self.key)

    def set_password(self, password):
        self.password = base64.b64encode(password)

    def get_password(self):
        return base64.b64decode(self.password)

    def check_password(self, password):
        kpdf = PBKDF2HMAC(
            algorithm=hashes.SHA256(),
            length=32,
            salt=SECRET,
            iterations=1000000,

# Path: pyledger/server/config.py
# SECRET = b'test'
# LIFETIME = 1
# 
# Path: pyledger/server/config.py
# SECRET = b'test'
# LIFETIME = 1


# Path: pyledger/server/db.py
import base64
from enum import Enum
from cryptography.exceptions import InvalidKey
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, \
    LargeBinary
from sqlalchemy import create_engine, desc
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship
from sqlalchemy.orm import sessionmaker, scoped_session
from pyledger.server.config import args
from pyledger.server.config import password_backend, SECRET

class User(Model):
    __tablename__ = 'users'
    id = Column(Integer, primary_key=True)
    name = Column(String, unique=True)
    when = Column(DateTime)
    info = Column(LargeBinary)
    key = Column(String)
    password = Column(String)
    profile = Column(Integer)
    contracts = relationship("Contract", back_populates="user")
    sessions = relationship("Session", back_populates='user')

    def __repr__(self):
        return '<User {} with key: {}>'.format(self.name, self.key)

    def __str__(self):
        return '<User {} with key: {}>'.format(self.name, self.key)

    def set_password(self, password):
        self.password = base64.b64encode(password)

    def get_password(self):
        return base64.b64decode(self.password)

    def check_password(self, password):
        kpdf = PBKDF2HMAC(
            algorithm=hashes.SHA256(),
            length=32,
            salt=SECRET,
            iterations=1000000,

            backend=password_backend