~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: me at id
  • Date: 2009-01-15 00:37:10 UTC
  • mto: This revision was merged to the branch mainline in revision 1090.
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:branches%2Fstorm:1141
ivle.database.User: Add an authenticate() method, and a hash_password()
     staticmethod to replace the auth functions in ivle.db.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
It also provides miscellaneous utility functions for database interaction.
25
25
"""
26
26
 
 
27
import md5
 
28
 
27
29
from storm.locals import create_database, Store, Int, Unicode, DateTime, \
28
30
                         Reference
29
31
 
90
92
    def __repr__(self):
91
93
        return "<%s '%s'>" % (type(self).__name__, self.login)
92
94
 
 
95
    def authenticate(self, password):
 
96
        """Validate a given password against this user.
 
97
 
 
98
        Returns True if the given password matches the password hash for this
 
99
        User, False if it doesn't match, and None if there is no hash for the
 
100
        user.
 
101
        """
 
102
        if self.passhash is None:
 
103
            return None
 
104
        return self.hash_password(password) == self.passhash
 
105
 
93
106
    def hasCap(self, capability):
94
107
        """Given a capability (which is a Role object), returns True if this
95
108
        User has that capability, False otherwise.
111
124
        fieldval = self.acct_exp
112
125
        return fieldval is not None and time.localtime() > fieldval
113
126
 
 
127
    @staticmethod
 
128
    def hash_password(password):
 
129
        return md5.md5(password).hexdigest()
 
130
 
114
131
    @classmethod
115
132
    def get_by_login(cls, store, login):
116
133
        """