Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8119633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:51:17+00:00 2026-06-06T04:51:17+00:00

Previously I have been investigating several solutions how to register with email address instead

  • 0

Previously I have been investigating several solutions how to register with email address instead of username. All the sources I found focus on creating a custom backend and rolling the Signup page. While this works for me, I couldn’t find a single solution that explains what to do with the login screen.

First of all my approach with Email authorization

Registration: I take the email address and create a hash of it as the username and store it.

Login: I take the email address again and create a hash of it and try
to find a username with the same hash.

How its done in code:

In the settings:

AUTHENTICATION_BACKENDS = ('MyApp.auth_backends.CustomUserModelBackend',)
CUSTOM_USER_MODEL = 'MyApp.CustomUser'

In models.py

class CustomUser(User):
    timezone = models.CharField(max_length=50, default='Europe/London')
    objects = UserManager()

I have customized the registration like this:

View.py

def register_page(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = CustomUser.objects.create_user(
                username=md5(form.cleaned_data['email']).digest().encode('base64')[:-1],
                password=form.cleaned_data['password2'],
                email=form.cleaned_data['email']
            )   

            return HttpResponseRedirect('/register/success/')
    else:
        form = RegistrationForm()
    variables = RequestContext(request, {'form':form})
    return render_to_response('registration/register.html', variables)

in auth_backends.CustomUserModelBackend:

calculate the hash of the given email address to find the related username.

class CustomUserModelBackend(ModelBackend):
    def authenticate(self, username=None, password=None):
        try:
            # The parameter Username is here really just the email address, I get 
            # the hash for the email parameter and try to find the user.

            hash_user = md5(username).digest().encode('base64')[:-1],
            user = self.user_class.objects.get(username=hash_user)
            if user.check_password(password):
                return user
        except self.user_class.DoesNotExist:
            return None

    def get_user(self, user_id):
        try:
            return self.user_class.objects.get(pk=user_id)
        except self.user_class.DoesNotExist:
            return None

    @property
    def user_class(self):
        if not hasattr(self, '_user_class'):
            self._user_class = get_model(*settings.CUSTOM_USER_MODEL.split('.', 2))
            if not self._user_class:
                raise ImproperlyConfigured('Could not get custom user model')
        return self._user_class

Now I am stuck with login screen.

I have done it like this, but I get redirected back to login screen without getting any error shown.

url.py

(r'^login/$', 'django.contrib.auth.views.login'),

registration/login.html

{% extends "base.html" %}
{% block title %}user login{% endblock %}
{% block head %}User login{% endblock %}
{% block content %}{% if form.errors %}
    <p>Your email and password didn't match</p>
{% endif %}
    <form action="." method="post">
        <p>
            <label for="id_username">Email:</label>{{ form.username }}
        </p>
        <p>
            <label for="id_password">Password:</label>{{ form.password }}
        </p>
        {% csrf_token %}
        <input type="hidden" name="next" value="/" />
        <input type="submit" value="login" />
    </form>
{% endblock %}

I know the solution is already problematic since I need an email input for “username” and not a charfield.

1) What do I have to do to override the field type?

2) I still can’t login, it says username doesn’t match password.

I debugged it in Authenticate and it doesnt find the user

            hash_user = md5(username).digest().encode('base64')[:-1],
            user = self.user_class.objects.get(username=hash_user)

Isn’t the hash of the same email address always the same? What could I be missing?

Update:

I can see clearly the hash code is saved as username in the database and I can see how within the Authenticate user = self.user_class.objects.get(username=hash_user) the hashcode is the same value as in the database. However it still doesn’t retrieve the user. Why?

enter image description here
enter image description here

UPDATE 2:

I found the problem. I had one comma there by mistake and that turned the hash into a tuple. Oh dear

This is correct and works:

hash_user = md5(username).digest().encode('base64')[:-1]
user = self.user_class.objects.get(username=hash_user)

We have now the full solution here. Just one thing.

Is anyone able to help me with 1) ? How can I override the username charfield please?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:51:18+00:00Added an answer on June 6, 2026 at 4:51 am

    Sadly, this is not currently possible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can a LINQ expression replace all cases where regex would have previously been used?
I have several remote repositories that I have been previously working with using Versions
Morning All, Previously I have been using $(#WebPartWPQ2 .ms-formtable tr:contains('lblName')> td).toggleClass('changedetails'); to customise a
I previously have been reading NMEA data from a GPS via a serial port
I have previously been told that I should always use Randomize() before I use
I believe this question might have been previously attempted in 2006 on a different
I'm looking to implement a REST client in PHP, and have previously been using
This must have been answered previously, but my Google powers are off today and
Basically, I am using Wireshark looking at captures that have been created previously. How
I have a database with existing data, where previously I've been using AUTO_INCREMENT on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.