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, '']
评论列表
文章目录