login with token instead of password

101 views
Skip to first unread message

ABDUL HAFEEZ

unread,
Jan 16, 2024, 10:03:04 AM1/16/24
to Django users
example: 
I have a model with fields username and password 
when users create account  there credentials saved in db next I want that instead of login with password I want create token so he can login with token not password

what should I do
please provide me logic steps if someone have done already

IKT Service

unread,
Jan 16, 2024, 10:05:31 AM1/16/24
to django...@googlegroups.com
Maybe try to send a token to user email, when used get that email with a activation link, he can just click and activate the account 

tir. 16. jan. 2024 kl. 16:02 skrev ABDUL HAFEEZ <ahafe...@gmail.com>:
example: 
I have a model with fields username and password 
when users create account  there credentials saved in db next I want that instead of login with password I want create token so he can login with token not password

what should I do
please en provide me logic steps if someone have done already

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e43d49a3-e950-4396-9f90-3b1cd6f7af0an%40googlegroups.com.

Ahmed Iftikhar

unread,
Jan 16, 2024, 10:20:20 AM1/16/24
to django...@googlegroups.com
python manage.py startapp pincode_auth_app
# pincode_auth_app/models.py from django.contrib.auth.models import AbstractUser from django.db import models class CustomUser(AbstractUser): pin_code = models.CharField(max_length=4, blank=True, null=True) 
***************
# pincode_auth_app/admin.py from django.contrib import admin from .models import CustomUser  
admin.site.register(CustomUser)
***********************
python manage.py makemigrations 
python manage.py migrate
********************************
# pincode_auth_app/forms.py from django import forms class PinCodeLoginForm(forms.Form): username = forms.CharField(max_length=150
pin_code = forms.CharField(max_length=4, widget=forms.PasswordInput)
*********************************
# pincode_auth_app/views.py from django.shortcuts import render, redirect from django.contrib.auth import authenticate, login from .forms import PinCodeLoginForm def pin_code_login(request): if request.method == 'POST': form = PinCodeLoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] pin_code = form.cleaned_data['pin_code'] user = authenticate(request, username=username, pin_code=pin_code) if user is not None: login(request, user) return redirect('success_page') # Redirect to a success page else: # Authentication failed return render(request, 'login.html', {'form': form, 'error': 'Invalid username or pin code'}) else: form = PinCodeLoginForm()  
return render(request, 'login.html', {'form': form})
*************************************
<!-- pincode_auth_app/templates/login.html --> <!DOCTYPE html> <html> <head> <title>Pin Code Login</title> </head> <body> <h2>Login</h2> {% if error %} <p style="color: red;">{{ error }}</p> {% endif %} <form method="post" action="{% url 'pin_code_login' %}"> {% csrf_token %} {{ form.as_p }} <button type="submit">Login</button> </form> </body> 
</html>
*******************************
  # pincode_auth/urls.py from django.urls import path from pincode_auth_app.views import pin_code_login urlpatterns = [ path('pin-code-login/', pin_code_login, name='pin_code_login'), # Add other URLs as needed ] 
*******************************************
# pincode_auth/urls.py from django.contrib import admin from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), path('', include('pincode_auth_app.urls')), 
] 


--

Kasper Laudrup

unread,
Jan 16, 2024, 11:49:49 AM1/16/24
to django...@googlegroups.com
Isn't this pincode_auth_app just the same as the standard Django
password authentication, only the password is stored in plain text and
limited to four characters?

Maybe I'm missing something?

Kind regards,
Kasper Laudrup
OpenPGP_0xE5D9CAC64AAA55EB.asc
OpenPGP_signature.asc
Reply all
Reply to author
Forward
0 new messages