Changeset 2826
- Timestamp:
- 04/05/07 16:23:13 (2 years ago)
- Files:
-
- branches/1.0/CHANGELOG.txt (modified) (3 diffs)
- branches/1.0/CONTRIBUTORS.txt (modified) (1 diff)
- branches/1.0/turbogears/identity/__init__.py (modified) (2 diffs)
- branches/1.0/turbogears/identity/saprovider.py (modified) (2 diffs)
- branches/1.0/turbogears/identity/soprovider.py (modified) (2 diffs)
- branches/1.0/turbogears/identity/tests/test_identity.py (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.0/CHANGELOG.txt
r2802 r2826 20 20 21 21 *Fixes* 22 23 * Identity now supports encrypted passwords with unicode characters. Thanks to Felix Schwarz and 24 Patrick Lewis #1281 22 25 * minor changes to template so they work properly when server.webpath != / thanks to "nludban" #1213 23 26 * fix quickstart project tests, thanks to Christoph Zwerschke #1289, Jeff Kowalczyk #1219 … … 30 33 31 34 *Project Updates* 35 32 36 * ez_setup.py version to 0.6c5 33 37 * Not require cElementTree, pysqlite in Python 2.5 install … … 35 39 *Contributors* 36 40 37 Alberto Valverde, Fred Lin, jorge.vargas, Joseph Tate, Elvelind Grandin, Florent Aide, nludban, Jeff Kowalczyk, corvus, Christoph Zwerschke, iberonasia, alastair, cito 41 Alberto Valverde, Fred Lin, jorge.vargas, Joseph Tate, Elvelind Grandin, Florent Aide, nludban, Jeff Kowalczyk, corvus, Christoph Zwerschke, iberonasia, alastair, cito, Felix Schwartz, Patrcik Lewis 38 42 39 43 branches/1.0/CONTRIBUTORS.txt
r2428 r2826 21 21 * Ondrej Zara (author of WWW SQL Designer) 22 22 * Irmen de Jong (author of Kronos) 23 * Florent Aide 24 * Travis Bradshaw 25 * Mark Ramm 23 26 24 27 Contributor Statement: branches/1.0/turbogears/identity/__init__.py
r2461 r2826 4 4 * Also want to support Atom authentication (similar to digest) 5 5 ''' 6 import md5 7 import sha 6 8 import threading 9 7 10 import cherrypy 8 11 import pkg_resources … … 113 116 from turbogears.identity.conditions import * 114 117 118 def _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 115 134 def encrypt_password(cleartext): 116 135 # this next one ultimately needs to change to support SQLAlchemy branches/1.0/turbogears/identity/saprovider.py
r2802 r2826 1 1 import cherrypy 2 import sha3 import md54 2 import random 5 3 from datetime import * … … 130 128 # Default encryption algorithm is to use plain text passwords 131 129 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) 138 132 139 133 def create_provider_model(self): branches/1.0/turbogears/identity/soprovider.py
r2421 r2826 1 import sha2 import md53 1 import random 4 2 … … 185 183 186 184 # 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 195 189 def create_provider_model( self ): 196 190 # create the database tables branches/1.0/turbogears/identity/tests/test_identity.py
r2556 r2826 1 # coding=UTF-8 1 2 import re 2 3 import unittest … … 154 155 155 156 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)." 157 158 hub.begin() 158 159 u = TG_User.by_user_name('samIam') … … 160 161 u.sync() 161 162 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') 162 178 hub.rollback() 163 179 hub.end() … … 171 187 hub.begin() 172 188 u = TG_User.by_user_name('samIam') 173 u.password ='password'189 u.password = 'password' 174 190 u.sync() 175 191 assert u.password =='5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8' 176 192 hub.rollback() 177 193 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() 178 209 179 210 def test_user_password_hashed_md5(self): 180 "Test if a shahashed password is stored in the database."211 "Test if a md5 hashed password is stored in the database." 181 212 config.update({'identity.soprovider.encryption_algorithm':'md5'}) 182 213 # force new config values to load … … 185 216 hub.begin() 186 217 u = TG_User.by_user_name('samIam') 187 u.password ='password'218 u.password = 'password' 188 219 u.sync() 189 220 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') 190 253 hub.rollback() 191 254 hub.end() … … 204 267 hub.rollback() 205 268 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 207 283 def test_anonymous_browsing(self): 208 284 "Test if we can show up anonymously."