<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def register(self, request, **kwargs):
 """ Create and immediately log in a new user. Only require a email to register, username is generated automatically and a password is random generated and emailed to the user. Activation is still required for account uses after specified number of days. """

        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)
        
        email = kwargs['email']
        
        # Generate random password
        password = User.objects.make_random_password()
        
        # Generate username based off of the email supplied
        username = sha_constructor(str(email)).hexdigest()[:30]
        
        incr = 0
        # Ensure the generated username is in fact unqiue
        while User.objects.filter(username=username).count() > 0:
            incr += 1
            username = sha_constructor(str(email + str(incr))).hexdigest()[:30]
        # Create the active user
        new_user = User.objects.create_user(username, email, password)
        new_user.save()
        
        # Create the registration profile, this is still needed because
        # the user still needs to activate there account for further users
        # after 3 days
        registration_profile = RegistrationProfile.objects.create_profile(
            new_user)
        
        # Authenticate and login the new user automatically
        auth_user = authenticate(username=username, password=password)
        login(request, auth_user)
        
        # Set the expiration to when the users browser closes so user
        # is forced to log in upon next visit, this should force the user
        # to check there email for there generated password.
        request.session.set_expiry(0)
        
        # Create a profile instance for the new user if 
        # AUTH_PROFILE_MODULE is specified in settings
        if hasattr(settings, 'AUTH_PROFILE_MODULE') and getattr(settings, 'AUTH_PROFILE_MODULE'):
            app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.')
            model = models.get_model(app_label, model_name)
            try:
                profile = new_user.get_profile()
            except model.DoesNotExist:
                profile = model(user=new_user)
                profile.save()   
                
        # Custom send activation email
        self.send_activation_email(
            new_user, registration_profile, password, site)  
        
        # Send user_registered signal
        signals.user_registered.send(sender=self.__class__,
                                     user=new_user,
                                     request=request)
        return new_user