Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable token length #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion drfpasswordless/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from django.conf import settings
import string
from django.utils.crypto import get_random_string
from drfpasswordless.settings import api_settings


def generate_hex_token():
return uuid.uuid1().hex
Expand All @@ -13,7 +15,7 @@ def generate_numeric_token():
Generate a random 6 digit string of numbers.
We use this formatting to allow leading 0s.
"""
return get_random_string(length=6, allowed_chars=string.digits)
return get_random_string(length=api_settings.PASSWORDLESS_TOKEN_LENGTH, allowed_chars=string.digits)


class CallbackTokenManger(models.Manager):
Expand Down
2 changes: 1 addition & 1 deletion drfpasswordless/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class AbstractBaseCallbackTokenSerializer(serializers.Serializer):

email = serializers.EmailField(required=False) # Needs to be required=false to require both.
mobile = serializers.CharField(required=False, validators=[phone_regex], max_length=15)
token = TokenField(min_length=6, max_length=6, validators=[token_age_validator])
token = TokenField(min_length=api_settings.PASSWORDLESS_TOKEN_LENGTH, max_length=api_settings.PASSWORDLESS_TOKEN_LENGTH, validators=[token_age_validator])

def validate_alias(self, attrs):
email = attrs.get('email', None)
Expand Down
3 changes: 3 additions & 0 deletions drfpasswordless/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
# Amount of time that tokens last, in seconds
'PASSWORDLESS_TOKEN_EXPIRE_TIME': 15 * 60,

# The length of the token to send in email or sms
'PASSWORDLESS_TOKEN_LENGTH': 6,

# The user's email field name
'PASSWORDLESS_USER_EMAIL_FIELD_NAME': 'email',

Expand Down