当前位置: 首页>>代码示例>>Python>>正文


Python bcrypt.BCRYPTPasswordManager类代码示例

本文整理汇总了Python中cryptacular.bcrypt.BCRYPTPasswordManager的典型用法代码示例。如果您正苦于以下问题:Python BCRYPTPasswordManager类的具体用法?Python BCRYPTPasswordManager怎么用?Python BCRYPTPasswordManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BCRYPTPasswordManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main():
    """Create a configured wsgi app"""
    settings = {}
    debug = os.environ.get('DEBUG', True)
    settings['reload_all'] = debug
    settings['debug_all'] = debug
    settings['auth.username'] = os.environ.get('AUTH_USERNAME', 'admin')
    manager = BCRYPTPasswordManager()
    settings['auth.password'] = os.environ.get(
        'AUTH_PASSWORD', manager.encode('secret'))
    if not os.environ.get('TESTING', False):
        # only bind the session if we are not testing
        engine = sa.create_engine(DATABASE_URL)
        DBSession.configure(bind=engine)
    # add a secret value for auth tkt signing
    auth_secret = os.environ.get('JOURNAL_AUTH_SECRET', 'itsaseekrit')
    # configuration setup
    config = Configurator(
        settings=settings,
        authentication_policy=AuthTktAuthenticationPolicy(
            secret=auth_secret,
            hashalg='sha512'
        ),
        authorization_policy=ACLAuthorizationPolicy(),
    )
    config.include('pyramid_tm')
    config.include('pyramid_jinja2')
    config.add_route('home', '/')
    config.add_route('add', '/add')
    config.add_route('login', '/login')
    config.add_route('logout', '/logout')
    config.add_static_view('static', os.path.join(HERE, 'static'))
    config.scan()
    app = config.make_wsgi_app()
    return app
开发者ID:hopestar06,项目名称:learning-journal,代码行数:35,代码来源:journal.py

示例2: main

def main(argv=None):
    if len(argv) != 3:
        print "Usage: create_user.py <username> <password>"
        sys.exit(1)

    session = dbsession()
    username = argv[1]
    password = argv[2]
    manager = BCRYPTPasswordManager()
    hashed_password = manager.encode(password)

    user = User()
    user.username = username
    user.password = hashed_password
    user.active_ind = True

    try:
        session.add(user)
        session.commit()
        print "User {0} created.".format(username)
    except:
        print "Error adding user."
        session.rollback()
        session.close()
        sys.exit(1)

    session.close()
    sys.exit(0)
开发者ID:antzucaro,项目名称:xonstat-queue,代码行数:28,代码来源:create_user.py

示例3: password_check

def password_check(password, stored_passw):
    """
    Returns a boolean of whether the password was correct.
    """
    from cryptacular.bcrypt import BCRYPTPasswordManager
    manager = BCRYPTPasswordManager()
    return manager.check(stored_passw, password)
开发者ID:BillSeitz,项目名称:webpy-blog-plus,代码行数:7,代码来源:blog.py

示例4: main

def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """

    @forbidden_view_config(renderer='templates/forbidden.jinja2')
    def forbidden(request):
        return {}

    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    auth_secret = os.environ.get('TASTEBUDDIES_AUTH_SECRET', 'tastynoms')

    authn_policy = AuthTktAuthenticationPolicy(
        secret=auth_secret,
        hashalg='sha512',
        callback=groupfinder,
    )

    authz_policy = ACLAuthorizationPolicy()

    settings['auth.username'] = os.environ.get('AUTH_USERNAME', 'admin')
    manager = BCRYPTPasswordManager()
    settings['auth.password'] = os.environ.get(
        'AUTH_PASSWORD', manager.encode('secret')
    )

    config = Configurator(
        settings=settings,
        authentication_policy=authn_policy,
        authorization_policy=authz_policy,
    )

    config.include('pyramid_jinja2')
    config.include('pyramid_tm')

    config.add_static_view('static', 'static', cache_max_age=3600)

    config.add_route('home', '/')
    config.add_route('user_create', '/create_user')
    config.add_route('user_login', '/login')
    config.add_route('verify', '/verify', factory=Root)
    config.add_route('send_email', '/send_email', factory=Root)
    config.add_route('logout', '/logout', factory=Root)
    config.add_route('profile_edit', '/profile/edit/{username}',
                     factory=Root)
    config.add_route('group_create', '/group/create_group',
                     factory=Root)
    config.add_route('group_edit', '/group/edit/{group_name}',
                     factory=Root)
    config.add_route('profile_detail', '/profile/{username}',
                     factory=UserFactory, traverse='/{username}')
    config.add_route('group_detail', '/group/{group_name}',
                     factory=Root)
    config.scan()

    return config.make_wsgi_app()
开发者ID:kaka0525,项目名称:taste-buddies,代码行数:58,代码来源:__init__.py

示例5: check_password

 def check_password(cls, username, password, session=None):
     if session is None:
         session = DBSession
     manager = BCRYPTPasswordManager()
     try:
         user = User.by_username(username)
     except NoResultFound:
         return False
     return manager.check(user.password, password)
开发者ID:jay-tyler,项目名称:email-reminder,代码行数:9,代码来源:models.py

示例6: login

def login(request):
    username = request.params.get("username", None)
    password = request.params.get("password", None)
    if not (username and password):
        raise ValueError("Username and password are required")
    manager = BCRYPTPasswordManager()
    try:
        user = User.get_by_username(username)
    except:
        raise ValueError("User does not exist")
    return manager.check(user.password, password)
开发者ID:tpeek,项目名称:Answer-Prediction,代码行数:11,代码来源:app.py

示例7: validate_user_password

    def validate_user_password(cls, username, password):
        user = DBSession.query(cls).options(noload(cls.groups)).filter(cls.username == username.lower()).first()

        if user is None:
            return None

        manager = BCRYPTPasswordManager()
        if manager.check(user.credentials, password):
            return user

        return None
开发者ID:bertjwregeer,项目名称:defcne,代码行数:11,代码来源:user.py

示例8: do_login

def do_login(request):
    username = request.params.get('username', None)
    password = request.params.get('password', None)
    if not (username and password):
        raise ValueError('both username and password are required')

    settings = request.registry.settings
    manager = BCRYPTPasswordManager()
    if username == settings.get('auth.username', ''):
        hashed = settings.get('auth.password', '')
        return manager.check(hashed, password)
开发者ID:gatita,项目名称:learning-journal,代码行数:11,代码来源:journal.py

示例9: _set_password

    def _set_password(self, raw_password):
        """ Encrypt the password.

        Encrypt `raw_password` with bcrypt and set it as the account
        password.

        :param raw_password: the unencrypted user password
        :type username: unicode
        :return: the bcrypt encrypted password
        :rtype: unicode
        """
        bcrypt = BCRYPTPasswordManager()
        self._password = unicode(bcrypt.encode(raw_password, rounds=12))
开发者ID:lazaret,项目名称:anuket,代码行数:13,代码来源:auth.py

示例10: test_create_user

def test_create_user(db_session):
    kwargs = {
        'username': "Test_Username",
        'password': "testpassword"
    }
    kwargs['session'] = db_session
    user = app.User.new(**kwargs)
    db_session.flush()
    u = db_session.query(app.User).filter(app.User.id == user.id).one()
    assert getattr(u, 'id', '') is not None
    assert getattr(u, 'username', '') == "Test_Username"
    manager = BCRYPTPasswordManager()
    assert manager.check(getattr(user, 'password', ''), "testpassword")
开发者ID:tpeek,项目名称:Answer-Prediction,代码行数:13,代码来源:test_app.py

示例11: new

 def new(cls, username=None, password=None, session=DBSession):
     """Stores password in database already hashed"""
     manager = BCRYPTPasswordManager()
     if not (username and password):
         raise ValueError("Username and password needed")
     hashed = unicode(manager.encode(password))
     try:
         instance = cls(username=username, password=hashed)
         session.add(instance)
         session.flush()
     except IntegrityError:
         raise ValueError("Username already in use")
     return instance
开发者ID:tpeek,项目名称:Answer-Prediction,代码行数:13,代码来源:app.py

示例12: auth_req

def auth_req(request):
    manager = BCRYPTPasswordManager()
    settings = {
        'auth.username': 'admin',
        'auth.password': manager.encode('secret'),
    }
    testing.setUp(settings=settings)
    req = testing.DummyRequest()

    def cleanup():
        testing.tearDown()
    request.addfinalizer(cleanup)
    return req
开发者ID:tpeek,项目名称:learning-journal,代码行数:13,代码来源:conftest.py

示例13: do_login

def do_login(request):
    username = request.params.get('username', None)
    password = request.params.get('password', None)
    if not (username and password):
        raise ValueError('both username and password are required')

    settings = request.registry.settings
    # you can always get hold of application settings with
    # `request.registry.settings`
    manager = BCRYPTPasswordManager()
    if username == settings.get('auth.username', ''):
        hashed = settings.get('auth.password', '')
        return manager.check(hashed, password)
    return False
开发者ID:tlake,项目名称:learning-journal,代码行数:14,代码来源:journal.py

示例14: do_login

def do_login(request):
    login_result = False
    manager = BCRYPTPasswordManager()

    entered_username = request.params.get('username', None)
    entered_password = request.params.get('password', None)

    user_obj = User.lookup_by_attribute(username=entered_username)[0]
    db_username = user_obj.username

    if entered_username == db_username:
        db_hashed = user_obj.password
        # manager.check returns BOOL
        login_result = manager.check(db_hashed, entered_password)

    return login_result
开发者ID:kaka0525,项目名称:taste-buddies,代码行数:16,代码来源:views.py

示例15: create_user

 def create_user(cls, username, password, first="", last="",
                 dflt_medium=1, timezone='America/Los_Angeles',
                 session=None):
     """Instantiates a new user, and writes it to the database.
     User must supply a username and password.
     """
     if session is None:
         session = DBSession
     manager = BCRYPTPasswordManager()
     hashed = manager.encode(password)
     instance = cls(first=first, last=last, username=username,
                    password=hashed, dflt_medium=dflt_medium,
                    timezone=timezone)
     session.add(instance)
     session.flush()
     return instance
开发者ID:jay-tyler,项目名称:email-reminder,代码行数:16,代码来源:models.py


注:本文中的cryptacular.bcrypt.BCRYPTPasswordManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。