# user.py """ Simple user class. 20010619 JJD Created. 20021115 JJD Remove group-related features and simplify. """ import sha from toa4.const import TAB, NULLSTRING class User: def __init__(self, username, password=NULLSTRING, new=0, securitylevel=0): """If new is nonzero, the password argument is assumed to be unencrypted, so it gets encrypted. Otherwise, the password is stored as-is.""" self._username = username if not new: self._password = password else: self._password = self._encrypt(password) self._securitylevel = securitylevel def validatePassword(self, word): return (self._encrypt(word) == self._password) def setPassword(self, newpassword): """The argument is an unencrypted string.""" self._password = self._encrypt(newpassword) def username(self): return self._username def securitylevel(self): return self._securitylevel def setSecuritylevel(self, n): self._securitylevel = n def dump(self): return self.__dict__.copy() def __str__(self): return self._username def __repr__ (self): return "<%s at %x: %s>" % (self.__class__.__name__, id(self), self._username) def _encrypt(self, word): x = sha.new(self._username.lower()+word+'__repr__') return x.hexdigest()