'Verifies that the password adheres to the reuse policies'

@classmethod
def is_allowable_password_reuse(cls, user, new_password):

    assert user
    if (not settings.FEATURES['ADVANCED_SECURITY']):
        return True
    if (user.is_staff and cls.is_staff_password_reuse_restricted()):
        min_diff_passwords_required = settings.ADVANCED_SECURITY_CONFIG['MIN_DIFFERENT_STAFF_PASSWORDS_BEFORE_REUSE']
    elif cls.is_student_password_reuse_restricted():
        min_diff_passwords_required = settings.ADVANCED_SECURITY_CONFIG['MIN_DIFFERENT_STUDENT_PASSWORDS_BEFORE_REUSE']
    else:
        min_diff_passwords_required = 0
    history = PasswordHistory.objects.filter(user=user).order_by('-time_set')[:min_diff_passwords_required]
    for entry in history:
        hash_elements = entry.password.split('$')
        algorithm = hash_elements[0]
        if (algorithm == 'pbkdf2_sha256'):
            hashed_password = make_password(new_password, hash_elements[2])
        elif (algorithm == 'sha1'):
            hashed_password = make_password(new_password, hash_elements[1])
        else:
            AUDIT_LOG.error('\n                                                                                                                                Unknown    password    hashing    algorithm    "{0}"    found    in    existing    password\n                                                                                                                                hash,    password    reuse    policy    will    not    be    enforced!!!\n                                                                                                                                '.format(algorithm))
            return True
        if (entry.password == hashed_password):
            return False
    return True
