Changeset 2826

Show
Ignore:
Timestamp:
04/05/07 16:23:13 (2 years ago)
Author:
alberto
Message:

Applied #1281 and updated CONTRIBUTORS.txt and CHANGELOG. Thanks Felix and Patrick

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/CHANGELOG.txt

    r2802 r2826  
    2020 
    2121*Fixes* 
     22 
     23* Identity now supports encrypted passwords with unicode characters. Thanks to Felix Schwarz and 
     24  Patrick Lewis #1281  
    2225* minor changes to template so they work properly when server.webpath != / thanks to "nludban" #1213 
    2326* fix quickstart project tests, thanks to Christoph Zwerschke #1289, Jeff Kowalczyk #1219 
     
    3033 
    3134*Project Updates* 
     35 
    3236* ez_setup.py version to 0.6c5 
    3337* Not require cElementTree, pysqlite in Python 2.5 install 
     
    3539*Contributors* 
    3640 
    37 Alberto Valverde, Fred Lin, jorge.vargas, Joseph Tate, Elvelind Grandin, Florent Aide, nludban, Jeff Kowalczyk, corvus, Christoph Zwerschke, iberonasia, alastair, cito 
     41Alberto Valverde, Fred Lin, jorge.vargas, Joseph Tate, Elvelind Grandin, Florent Aide, nludban, Jeff Kowalczyk, corvus, Christoph Zwerschke, iberonasia, alastair, cito, Felix Schwartz, Patrcik Lewis 
    3842 
    3943 
  • branches/1.0/CONTRIBUTORS.txt

    r2428 r2826  
    2121* Ondrej Zara (author of WWW SQL Designer) 
    2222* Irmen de Jong (author of Kronos) 
     23* Florent Aide 
     24* Travis Bradshaw 
     25* Mark Ramm 
    2326 
    2427Contributor Statement: 
  • branches/1.0/turbogears/identity/__init__.py

    r2461 r2826  
    44    * Also want to support Atom authentication (similar to digest) 
    55''' 
     6import md5 
     7import sha 
    68import threading 
     9 
    710import cherrypy 
    811import pkg_resources 
     
    113116from turbogears.identity.conditions import * 
    114117 
     118def _encrypt_password(algorithm, password): 
     119    """Hash the given password with the specified algorithm. Valid values 
     120    for algorithm are 'md5' and 'sha1'. All other algorithm values will 
     121    be essentially a no-op.""" 
     122    if isinstance(password, unicode): 
     123        password_8bit = password.encode('UTF-8') 
     124    else: 
     125        password_8bit = password 
     126    if "md5" == algorithm: 
     127        hashed_password =  md5.new(password_8bit).hexdigest() 
     128    elif "sha1" == algorithm: 
     129        hashed_password = sha.new(password_8bit).hexdigest() 
     130    else: 
     131        hashed_password = password 
     132    return hashed_password    
     133 
    115134def encrypt_password(cleartext): 
    116135    # this next one ultimately needs to change to support SQLAlchemy 
  • branches/1.0/turbogears/identity/saprovider.py

    r2802 r2826  
    11import cherrypy 
    2 import sha 
    3 import md5 
    42import random 
    53from datetime import * 
     
    130128        # Default encryption algorithm is to use plain text passwords 
    131129        algorithm = get("identity.saprovider.encryption_algorithm", None) 
    132         if "md5"==algorithm: 
    133             self.encrypt_password = lambda pw: md5.new(pw).hexdigest() 
    134         elif "sha1"==algorithm: 
    135             self.encrypt_password = lambda pw: sha.new(pw).hexdigest() 
    136         else: 
    137             self.encrypt_password = lambda pw: pw 
     130        self.encrypt_password = lambda pw: \ 
     131                                    identity._encrypt_password(algorithm, pw) 
    138132 
    139133    def create_provider_model(self): 
  • branches/1.0/turbogears/identity/soprovider.py

    r2421 r2826  
    1 import sha 
    2 import md5 
    31import random 
    42 
     
    185183             
    186184        # Default encryption algorithm is to use plain text passwords 
    187         algorithm= get( "identity.soprovider.encryption_algorithm", None ) 
    188         if "md5"==algorithm: 
    189             self.encrypt_password= lambda pw: md5.new(pw).hexdigest() 
    190         elif "sha1"==algorithm: 
    191             self.encrypt_password= lambda pw: sha.new(pw).hexdigest() 
    192         else: 
    193             self.encrypt_password= lambda pw: pw 
    194  
     185        algorithm = get("identity.soprovider.encryption_algorithm", None) 
     186        self.encrypt_password = lambda pw: \ 
     187                                    identity._encrypt_password(algorithm, pw) 
     188             
    195189    def create_provider_model( self ): 
    196190        # create the database tables 
  • branches/1.0/turbogears/identity/tests/test_identity.py

    r2556 r2826  
     1# coding=UTF-8 
    12import re 
    23import unittest 
     
    154155 
    155156    def test_user_password(self): 
    156         "Test if we can set a user password (no encryption algorithm)
     157        "Test if we can set a user password (no encryption algorithm).
    157158        hub.begin() 
    158159        u = TG_User.by_user_name('samIam') 
     
    160161        u.sync() 
    161162        assert u.password=='password' 
     163        hub.rollback() 
     164        hub.end() 
     165         
     166    def test_user_password_unicode(self): 
     167        """Test if we can set a user password which is encoded as unicode (no  
     168        encryption algorithm).""" 
     169        config.update({'identity.soprovider.encryption_algorithm':None}) 
     170        # force new config values to load 
     171        startup.startTurboGears() 
     172        testutil.create_request('/') 
     173        hub.begin() 
     174        u = TG_User.by_user_name('samIam') 
     175        u.password = u'garçon' 
     176        u.sync() 
     177        self.assertEqual(u.password, u'garçon') 
    162178        hub.rollback() 
    163179        hub.end() 
     
    171187        hub.begin() 
    172188        u = TG_User.by_user_name('samIam') 
    173         u.password='password' 
     189        u.password = 'password' 
    174190        u.sync() 
    175191        assert u.password =='5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8' 
    176192        hub.rollback() 
    177193        hub.end() 
     194         
     195    def test_user_password_hashed_sha_unicode(self): 
     196        """Test if a sha hashed password with unicode characters is stored in  
     197        the database.""" 
     198        config.update({'identity.soprovider.encryption_algorithm':'sha1'}) 
     199        # force new config values to load 
     200        startup.startTurboGears() 
     201        testutil.create_request('/') 
     202        hub.begin() 
     203        u = TG_User.by_user_name('samIam') 
     204        u.password = u'garçon' 
     205        u.sync() 
     206        self.failUnlessEqual(u.password, '442edb21c491a6e6f502eb79e98614f3c7edf43e') 
     207        hub.rollback() 
     208        hub.end() 
    178209 
    179210    def test_user_password_hashed_md5(self): 
    180         "Test if a sha hashed password is stored in the database." 
     211        "Test if a md5 hashed password is stored in the database." 
    181212        config.update({'identity.soprovider.encryption_algorithm':'md5'}) 
    182213        # force new config values to load 
     
    185216        hub.begin() 
    186217        u = TG_User.by_user_name('samIam') 
    187         u.password='password' 
     218        u.password = 'password' 
    188219        u.sync() 
    189220        assert u.password =='5f4dcc3b5aa765d61d8327deb882cf99' 
     221        hub.rollback() 
     222        hub.end() 
     223         
     224    def test_user_password_hashed_md5_unicode(self): 
     225        """Test if a md5 hashed password with unicode characters is stored in  
     226        the database.""" 
     227        config.update({'identity.soprovider.encryption_algorithm':'md5'}) 
     228        # force new config values to load 
     229        startup.startTurboGears() 
     230        testutil.create_request('/') 
     231        hub.begin() 
     232        u = TG_User.by_user_name('samIam') 
     233        u.password = u'garçon' 
     234        u.sync() 
     235        self.assertEqual(u.password, 'c295c4bb2672ca8c432effc53b40bb1e') 
     236        hub.rollback() 
     237        hub.end() 
     238 
     239    def test_user_password_hashed_md5_utf8string(self): 
     240        """Test if a md5 hashed password with unicode characters is stored in  
     241        the database if the password is entered as str (encoded in UTF-8). This 
     242        test ensures that the encryption algorithm does handle non-unicode 
     243        parameters gracefully.""" 
     244        config.update({'identity.soprovider.encryption_algorithm':'md5'}) 
     245        # force new config values to load 
     246        startup.startTurboGears() 
     247        testutil.create_request('/') 
     248        hub.begin() 
     249        u = TG_User.by_user_name('samIam') 
     250        u.password = u'garçon'.encode('UTF-8') 
     251        u.sync() 
     252        self.assertEqual(u.password, 'c295c4bb2672ca8c432effc53b40bb1e') 
    190253        hub.rollback() 
    191254        hub.end() 
     
    204267        hub.rollback() 
    205268        hub.end() 
    206  
     269         
     270    def test_user_password_raw_unicode(self): 
     271        config.update({'identity.soprovider.encryption_algorithm':'sha1'}) 
     272        # force new config values to load 
     273        startup.startTurboGears() 
     274        testutil.create_request('/') 
     275        hub.begin() 
     276        u = TG_User.by_user_name('samIam') 
     277        u.set_password_raw(u'garçon') 
     278        u.sync() 
     279        self.assertEqual(u.password, u'garçon') 
     280        hub.rollback() 
     281        hub.end() 
     282         
    207283    def test_anonymous_browsing(self): 
    208284        "Test if we can show up anonymously."