{{{
@classmethod
def hash_password(cls, password):
"""From a clear text password, return a hashed password."""
hashed_password = password
if isinstance(password, unicode):
password_8bit = password.encode('UTF-8')
else:
password_8bit = password
salt = sha1()
salt.update(os.urandom(60))
hash = sha1()
hash.update(password_8bit + salt.hexdigest())
hashed_password = salt.hexdigest() + hash.hexdigest()
# make sure the hased password is an UTF-8 object at the end of
the
# process because SQLAlchemy _wants_ a unicode object for Unicode
columns
if not isinstance(hashed_password, unicode):
hashed_password = hashed_password.decode('UTF-8')
return hashed_password
def _set_password(self, password):
"""Hash password on the fly."""
self._password = self.hash_password(password)
}}}
--
Ticket URL: <http://trac.turbogears.org/ticket/2283>
TurboGears <http://www.turbogears.org/>
TurboGears front-to-back web development
* keywords: => authentication, model
* owner: => Gustavo
* status: new => assigned
* milestone: 2.0rc1 => 2.1
Comment:
Sounds good.
--
Ticket URL: <http://trac.turbogears.org/ticket/2283#comment:1>
Why not go the whole way and make it a static method? Not that it makes
a big difference, but hash_password doesn't need cls or self...
--
Ticket URL: <http://trac.turbogears.org/ticket/2283#comment:2>
Well, I can't think of a case where a staticmethod would be more useful
than a classmethod. I find classmethods generally more flexible (but since
the calling convention is the same I agree it doesn't make much of a
difference, it can be changed back later).
--
Ticket URL: <http://trac.turbogears.org/ticket/2283#comment:3>
Replying to [comment:2 mramm]:
> Why not go the whole way and make it a static method? Not that it
makes a big difference, but hash_password doesn't need cls or self...
+1
--
Ticket URL: <http://trac.turbogears.org/ticket/2283#comment:4>
* milestone: 2.1 => 2.2
--
Ticket URL: <http://trac.turbogears.org/ticket/2283#comment:5>