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


Python BCRYPTPasswordManager.check方法代码示例

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


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

示例1: test_shorthash

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
 def test_shorthash(self):
     manager = BCRYPTPasswordManager()
     def match(hash):
         return True
     manager.match = match
     short_hash = manager.encode(self.snowpass)[:28]
     assert_true(manager.match(short_hash))
     manager.check(short_hash, self.snowpass)
开发者ID:ahlusar1989,项目名称:learning_journal,代码行数:10,代码来源:test_bcrypt.py

示例2: password_check

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
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,代码行数:9,代码来源:blog.py

示例3: check_password

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
 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,代码行数:11,代码来源:models.py

示例4: do_login

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
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,代码行数:13,代码来源:journal.py

示例5: validate_user_password

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
    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,代码行数:13,代码来源:user.py

示例6: login

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
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,代码行数:13,代码来源:app.py

示例7: test_create_user

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
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,代码行数:15,代码来源:test_app.py

示例8: do_login

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
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,代码行数:16,代码来源:journal.py

示例9: do_login

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
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,代码行数:18,代码来源:views.py

示例10: check_password

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
    def check_password(cls, username, password):
        """ Check the user password.

        Check if the submited password for username is the same than the
        encrypted one recorded in the database. Return None if the username
        did not exist.

        :param username: the user username
        :type username: unicode
        :param username: the submited password
        :type username: unicode
        :return: True if the password is correct. false if incorect
        :rtype: boolean
        """
        bcrypt = BCRYPTPasswordManager()
        user = cls.get_by_username(username)
        if user:
            return bcrypt.check(user.password, password)
开发者ID:lazaret,项目名称:anuket,代码行数:20,代码来源:auth.py

示例11: login

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
    def login(self):
        max_logins = 6
        request = self.request
        login_url = request.route_url('login_path')
        referrer = request.url
        if referrer == login_url:
            referrer = '/'  # never use login form itself as came_from
        came_from = request.params.get('came_from', referrer)
        login = None
        password = None
        flash_messages = []

        if 'form.submitted' in request.params:
            if('login' in request.params and request.params['login'] != None):
                login = request.params['login']
            else:
                flash_messages.append('No email address provided.')

            if('password' in request.params and request.params['password'] != None):
                password = request.params['password']
            else:
                flash_messages.append('No password entered.')

            #Check that this user hasn't gone over their maximum number of login attempts
            four_hours_ago = dt.datetime.now() - dt.timedelta(hours = 4)
            failed_login_count = request.db.query(FailedLogin).filter(and_(or_(FailedLogin.email == login,
            FailedLogin.ip_address == request.remote_addr),
            FailedLogin.date_of_failure >= four_hours_ago)).count()

            if failed_login_count <= max_logins:
                if(login != None and password != None):
                    #Start by finding this user in the database
                    user = request.db.query(RegisteredUser).filter(RegisteredUser.email == login).first()

                    #Create the crypto_manager
                    crypto_manager = BCRYPTPasswordManager()

                    #If they exist, let's verify that this is their password
                    if(user and crypto_manager.check(user.getPassword(), password)):
                        #Create a random number and fill in the database with key information
                        #This is done in a while loop using the was_created sentinal variable to insure that
                        #we did not accidently create two different sessions with the same session key value
                        #If this should happen, we will retry logging the user in.
                        was_not_created = True
                        iter_value = 0
                        while was_not_created:
                            try:
                                iter_value += 1
                                if(iter_value < 10):
                                    new_session_key = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits + string.ascii_lowercase) for _ in range(64))
                                    user_session = SessionCookie(
                                        session_key = new_session_key,
                                        user_id = user.id,
                                        user_role = request.db.query(UserGroup).filter(UserGroup.id == user.getGroupId()).first().getName(),
                                        creation_date = dt.datetime.now(),
                                        expiration_date = dt.datetime.now() + dt.timedelta(minutes = 20),
                                        update_time = dt.datetime.now() + dt.timedelta(minutes = 2)
                                    )
                                    request.db.add(user_session)
                                    request.db.commit()
                                    request.db.flush()
                                    was_not_created = False
                            except exc.SQLAlchemyError as e:
                                print e
                                request.db.rollback()
                                was_not_created = True

                        request.session['session_key'] = new_session_key
                        headers = remember(request, new_session_key)
                        request.session.flash("You have successfully logged in to your account.", "success")
                        return HTTPFound(location=came_from, headers=headers)
                    else:
                        #Tell the user their login failed.
                        flash_messages.append('Invalid e-mail/password.')

                        #Increase the number failed logins recorded
                        failed_login = FailedLogin(email=login,
                            date_of_failure=dt.datetime.now(),
                            ip_address=request.remote_addr)

                        request.db.add(failed_login)

                        logEntry = LogItem(event_name = 'Failed Login Attempt',
                        event_description = 'A user attempted to log into the user with email, {0}, using invalid login credentials.'.format(login),
                        event_tag_id = None,
                        user_id = None,
                        ip_address = request.remote_addr,
                        danger_index = 1,
                        event_date = dt.datetime.now())
                        request.db.add(logEntry)

                        request.db.commit()

                        #Increase the number of failed logins on this user (if they entered a valid login email)
                        if(user):
                            if(user.getNumberOfFailedLogins() != None):
                                new_failed_login_count = user.getNumberOfFailedLogins() + 1
                            else:
                                new_failed_login_count = 1
                            user.num_of_failed_logins = new_failed_login_count
#.........这里部分代码省略.........
开发者ID:Dante83,项目名称:lexinomicon,代码行数:103,代码来源:authentication_view.py

示例12: verify_password

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
 def verify_password(self, password):
     manager = Manager()
     return manager.check(self.password, password)
开发者ID:ahlusar1989,项目名称:learning_journal,代码行数:5,代码来源:models.py

示例13: check_password

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
 def check_password(self, password):
     manager = BCRYPTPasswordManager()
     return manager.check(self.credentials, password)
开发者ID:rmoorman,项目名称:usingnamespace,代码行数:5,代码来源:user.py

示例14: validate_password

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
 def validate_password(self, value):
     manager = BCRYPTPasswordManager()
     return manager.check(self._password, value)
开发者ID:byronh,项目名称:dashto.net,代码行数:5,代码来源:models.py

示例15: TestBCRYPTPasswordManager

# 需要导入模块: from cryptacular.bcrypt import BCRYPTPasswordManager [as 别名]
# 或者: from cryptacular.bcrypt.BCRYPTPasswordManager import check [as 别名]
class TestBCRYPTPasswordManager(object):
    snowpass = "hashy the \N{SNOWMAN}"

    def setup(self):
        self.manager = BCRYPTPasswordManager()

    @raises(TypeError)
    def test_None1(self):
        self.manager.encode(None)

    @raises(TypeError)
    def test_None2(self):
        self.manager.check(None, 'xyzzy')

    @raises(TypeError)
    def test_None3(self):
        hash = self.manager.encode('xyzzy')
        self.manager.check(hash, None)

    def test_badhash(self):
        eq_(self.manager.check('$p5k2$400$ZxK4ZBJCfQg=$kBpklVI9kA13kP32HMZL0rloQ1M=', self.snowpass), False)

    @raises(ValueError)
    def test_shorthash(self):
        manager = BCRYPTPasswordManager()
        def match(hash):
            return True
        manager.match = match
        short_hash = manager.encode(self.snowpass)[:28]
        assert_true(manager.match(short_hash))
        manager.check(short_hash, self.snowpass)

    @raises(ValueError)
    def test_too_few_rounds(self):
        self.manager.encode(self.snowpass, rounds=1)

    @raises(ValueError)
    def test_too_many_rounds(self):
        self.manager.encode(self.snowpass, rounds=100)

    def test_emptypass(self):
        self.manager.encode('')

    def test_general(self):
        manager = self.manager
        hash = manager.encode(self.snowpass)
        eq_(manager.match(hash), True)
        eq_(len(hash), 60)
        assert_true(manager.check(hash, self.snowpass))
        password = "xyzzy"
        hash = manager.encode(password)
        assert_true(manager.check(hash, password))
        assert_true(manager.check(unicode(hash), password))
        assert_false(manager.check(password, password))
        assert_not_equal(manager.encode(password), manager.encode(password))
        hash = manager.encode(password, rounds=4)
        assert_true(manager.check(hash, password))
    
    @raises(ValueError)
    def test_fail_1(self):
        def return_none(*args): return None
        bcrypt = BCRYPTPasswordManager()
        bcrypt.crypt_gensalt_rn = return_none
        bcrypt.encode('foo')

    @raises(ValueError)
    def test_fail_2(self):
        def return_none(*args): return None
        bcrypt = BCRYPTPasswordManager()        
        bcrypt.crypt_rn = return_none
        bcrypt.encode('foo')

    @raises(ValueError)
    def test_fail_3(self):
        def return_none(*args): return None
        bcrypt = BCRYPTPasswordManager()
        pw = bcrypt.encode('foobar')
        bcrypt.crypt_rn = return_none
        bcrypt.check(pw, 'foo')
开发者ID:ahlusar1989,项目名称:learning_journal,代码行数:81,代码来源:test_bcrypt.py


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