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

  • Home
  • SEARCH
  • 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 6348939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:31:04+00:00 2026-05-24T21:31:04+00:00

I’m trying to provide a user registration form without requiring a username to be

  • 0

I’m trying to provide a user registration form without requiring a username to be manually entered. I setup an authentication backend so that users can authenticate with an email address and that works because I can login with the Django admin user. The idea is that my app would create a SHA1 hash of the email address to be stored as the Django username and the user would never see this.

I removed the username field from my registration html template, but I’m not sure how or where I should be generating the username programmatically. I think it should be in the clean_username method of the RegistrationForm, but that method doesn’t get called when I use a template without the username field.

Any help would certainly be appreciated.

  • 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-05-24T21:31:05+00:00Added an answer on May 24, 2026 at 9:31 pm

    I got it to work. I don’t feel good about having to modify the registration’s view method and the default registration backend directly. I’d prefer to have those changes in my own code and am still working to make those changes, but this does indeed work.

    Here’s how I did it:

    1. Created a custom registration backend called RegBackend that generates a sha1 hash based on the email address and then stores the hexdigest as the username, finally returning a User object.

    2. Map register in urls.py to the new RegBackend that I created in step 1

    3. Modified the django-registration’s view register method to create a random username so that the form validates, but I never persist the random username. I copied the request.POST dictionary and set this random username to one of the copy’s dictionary keys called data[‘username’]. Then I use the data variable when creating an instance of the form_class. Calling is_valid() on the form would return false because I removed the username from the template, but Django requires a username for registration, so I needed to supply it something.

    I didn’t use the sha1 hash for the random username because the Django username can only be 30 characters in length while the sha1 hash is 40. Oddly, the custom registration backend didn’t complain and can store the sha1 hash, but the form would generate errors because of the length when submitted.

    _init_.py (I copied the existing DefaultBackend and modified with the SHA1 portion)

    from django.conf import settings
    from django.contrib.sites.models import RequestSite
    from django.contrib.sites.models import Site
    
    from registration import signals
    from registration.forms import RegistrationForm
    from registration.models import RegistrationProfile
    
    import hashlib
    
    class RegBackend(object):
    
    def register(self, request, **kwargs):
    
    hash_user = hashlib.sha1()
    hash_user.update(kwargs['email'])
    
        username, email, password = hash_user.hexdigest(), kwargs['email'], kwargs['password1']
    
        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)
        new_user = RegistrationProfile.objects.create_inactive_user(username, email,
                                                                    password, site)
        signals.user_registered.send(sender=self.__class__,
                                     user=new_user,
                                     request=request)
        return new_user
    
        #omitted other code from DefaultBackend that I didn't modify
    

    urls.py

    url(r'^register/$', register, {'backend': 'registration.backends.default.RegBackend', 'form_class': UserRegistrationForm}, name='registration_register'),
    

    registration/views.py

    def register(request, backend, success_url=None, form_class=None,
                 disallowed_url='registration_disallowed',
                 template_name='registration/registration_form.html',
                 extra_context=None):
    
        backend = get_backend(backend)
        if not backend.registration_allowed(request):
            return redirect(disallowed_url)
        if form_class is None:
            form_class = backend.get_form_class(request)
    
        if request.method == 'POST':
            # I added the next two lines
            data = request.POST.copy()
            data['username'] = ''.join([choice(letters) for i in xrange(30)])
            form = form_class(data=data, files=request.FILES)
            if form.is_valid():
                new_user = backend.register(request, **form.cleaned_data)
                if success_url is None:
                    to, args, kwargs = backend.post_registration_redirect(request, new_user)
                    return redirect(to, *args, **kwargs)
                else:
                    return redirect(success_url)
    
        else:
            form = form_class()
    
        if extra_context is None:
            extra_context = {}
        context = RequestContext(request)
        for key, value in extra_context.items():
            context[key] = callable(value) and value() or value
    
        return render_to_response(template_name,
                                  {'form': form},
                                  context_instance=context)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a

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.