auth.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:varapp-backend-py 作者: varapp 项目源码 文件源码
def check_credentials(username, password):
    """Compare the crypted password of this user with the one stored in the db.
    Return the User instance if authenticated successfully.
    """
    users_with_that_name = Users.objects.filter(username=username)
    if not users_with_that_name:
        return [None, "User '{}' does not exist".format(username)]
    active_users_with_that_name = users_with_that_name.filter(is_active=1)
    if not active_users_with_that_name:
        return [None, "Account '{}' has not been activated".format(username)]
    user = users_with_that_name[0]
    users_with_that_name_and_pwd = users_with_that_name.filter(password=crypt.crypt(password, user.salt))
    if not users_with_that_name_and_pwd:
        return [None, "Wrong password"]
    user = users_with_that_name_and_pwd[0]
    return [user, '']
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号