I try to implement this <https://djangosnippets.org/snippets/3030/> hasher 
in order to be able to authenticate user who are imported from drupal 7. 

So I put the hasher in the settings.py as follows:


PASSWORD_HASHERS = (
    
    'myproj.drupal_hasher.DrupalPasswordHasher', #drupal hasher
     
    'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
    
    'django.contrib.auth.hashers.BCryptPasswordHasher',
    'django.contrib.auth.hashers.SHA1PasswordHasher',
    'django.contrib.auth.hashers.MD5PasswordHasher',
    'django.contrib.auth.hashers.CryptPasswordHasher',
     ) 



However it does not authenticate imported users from drupal and for users 
who are created in Django I get:

    'ascii' codec can't decode byte 0xcf in position 0: ordinal not in 
range(128)




Here is the trackback:


    Environment:
    
    
    Request Method: POST
    Request URL: http://127.0.0.1:8000/auth/
    
    Django Version: 1.7.3
    Python Version: 2.7.3
    Installed Applications:
    ('django.contrib.admin',
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
     'article',
     'photo',
     'debug_toolbar',
     'django_markdown',
     'haystack')
    Installed Middleware:
    (u'debug_toolbar.middleware.DebugToolbarMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.common.CommonMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware',
     'django.middleware.clickjacking.XFrameOptionsMiddleware')
    
    
    Traceback:
    File 
"/home/mario/.myprojenv/local/lib/python2.7/site-packages/django/core/handlers/base.py"
 
in get_response
      111.                     response = wrapped_callback(request, *
callback_args, **callback_kwargs)
    File "/home/mario/myproj/myauth/views.py" in auth_view
      16.     user = auth.authenticate(username=username, password=password)
    File 
"/home/mario/.myprojenv/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py"
 
in authenticate
      60.             user = backend.authenticate(**credentials)
    File 
"/home/mario/.myprojenv/local/lib/python2.7/site-packages/django/contrib/auth/backends.py"
 
in authenticate
      17.             if user.check_password(password):
    File 
"/home/mario/.myprojenv/local/lib/python2.7/site-packages/django/contrib/auth/models.py"
 
in check_password
      237.         return check_password(raw_password, self.password, setter
)
    File 
"/home/mario/.myprojenv/local/lib/python2.7/site-packages/django/contrib/auth/hashers.py"
 
in check_password
      63.         setter(password)
    File 
"/home/mario/.myprojenv/local/lib/python2.7/site-packages/django/contrib/auth/models.py"
 
in setter
      235.             self.set_password(raw_password)
    File 
"/home/mario/.myprojenv/local/lib/python2.7/site-packages/django/contrib/auth/models.py"
 
in set_password
      227.         self.password = make_password(raw_password)
    File 
"/home/mario/.myprojenv/local/lib/python2.7/site-packages/django/contrib/auth/hashers.py"
 
in make_password
      85.     return hasher.encode(password, salt)
    File "/home/mario/myproj/myproj/drupal_hasher.py" in encode
      81.         encoded_hash = self._apply_hash(password, self._digests[
digest], settings)
    File "/home/mario/myproj/myproj/drupal_hasher.py" in _apply_hash
      68.             password_hash = digest(password_hash + password).
digest()
    
    Exception Type: UnicodeDecodeError at /auth/
    Exception Value: 'ascii' codec can't decode byte 0xcf in position 0: 
ordinal not in range(128)


All source and destination database tables are converted to utf8_unicode_ci.

I am stock on this problem for days so really appreciate your help. 



-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5dd15420-01d5-4b1f-adf0-af3ee585ba73%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to