def doChangeUser(self, principal_id, password): """ Update user's password date and store passwords history. """ user = api.user.get(username=principal_id) portal = api.portal.get() current_time = portal.ZopeTime() user.setMemberProperties({'password_date': current_time}) self._invalidatePrincipalCache(principal_id) # Remember passwords here max_history_pws = api.portal.get_registry_record( 'collective.pwexpiry.password_history_size' ) if max_history_pws == 0: # disabled, return here. return enc_pw = password if not AuthEncoding.is_encrypted(enc_pw): enc_pw = AuthEncoding.pw_encrypt(enc_pw) pw_history = list(user.getProperty('password_history', tuple())) pw_history.append(enc_pw) if len(pw_history) > max_history_pws: # Truncate the history pw_history = pw_history[-max_history_pws:] user.setMemberProperties({'password_history': tuple(pw_history)})
def doChangeUser(self, principal_id, password): """ Update user's password date and store passwords history. """ user = api.user.get(username=principal_id) portal = api.portal.get() current_time = portal.ZopeTime() user.setMemberProperties({"password_date": current_time}) self._invalidatePrincipalCache(principal_id) # Remember passwords here max_history_pws = api.portal.get_registry_record( "collective.pwexpiry.password_history_size" ) if max_history_pws == 0: # disabled, return here. return enc_pw = password if not AuthEncoding.is_encrypted(enc_pw): enc_pw = AuthEncoding.pw_encrypt(enc_pw) pw_history = list(user.getProperty("password_history", tuple())) pw_history.append(enc_pw) if len(pw_history) > max_history_pws: # Truncate the history pw_history = pw_history[-max_history_pws:] user.setMemberProperties({"password_history": tuple(pw_history)})
def authenticateCredentials(self, credentials): """ See IAuthenticationPlugin. o We expect the credentials to be those returned by ILoginPasswordExtractionPlugin. """ login = credentials.get('login') password = credentials.get('password') if login is None or password is None: return None userid = self._login_to_userid.get(login, login) reference = self._user_passwords.get(userid) if reference is None: return None if AuthEncoding.is_encrypted(reference): if AuthEncoding.pw_validate(reference, password): return userid, login # Support previous naive behavior digested = sha.sha(password).hexdigest() if reference == digested: return userid, login return None
def authenticateCredentials(self, credentials): """ Fulfill AuthenticationPlugin requirements """ acl = self._getUserFolder() login = credentials.get('login', '') password = credentials.get('password', '') if not acl or not login or not password: return (None, None) if ( login == emergency_user.getUserName() and AuthEncoding.pw_validate( emergency_user._getPassword(), password ) ): return (login, login) user = acl.getUser(login) if user is None: return (None, None) elif user and AuthEncoding.pw_validate(user._getPassword(), password): return (user.getId(), login) return (None, None)
def authenticateCredentials( self, credentials ): """ See IAuthenticationPlugin. o We expect the credentials to be those returned by ILoginPasswordExtractionPlugin. """ login = credentials.get( 'login' ) password = credentials.get( 'password' ) if login is None or password is None: return None userid = self._login_to_userid.get( login, login ) reference = self._user_passwords.get(userid) if reference is None: return None if AuthEncoding.is_encrypted( reference ): if AuthEncoding.pw_validate( reference, password ): return userid, login # Support previous naive behavior digested = sha.sha( password ).hexdigest() if reference == digested: return userid, login return None
def setAttempt(self, login, password): """ Set counter to 1 or bump it when authentication failed, if previous failed attempt was more than reset period time instead of bumping counter reset it to 1 """ root = self.getRootPlugin() count, last, IP, reference = root._login_attempts.get( login, (0, None, '', None)) if reference and AuthEncoding.pw_validate(reference, password): # don't count repeating same password return if last: delta = DateTime().asdatetime() - last.asdatetime() if delta.seconds > self.getResetPeriod(): # set counter to 1 instead of bumping, some sort of autoreset. count = 1 else: count += 1 else: count += 1 IP = self.remote_ip() log.debug("user '%s' failed to login, attempt #%i %s last: %s", login, count, IP, last) last = DateTime() reference = AuthEncoding.pw_encrypt(password) root._login_attempts[login] = (count, last, IP, reference)
def testBlankPassword(self): pw = '' for id in AuthEncoding.listSchemes(): enc = AuthEncoding.pw_encrypt(pw, id) assert enc != pw assert AuthEncoding.pw_validate(enc, pw) assert not AuthEncoding.pw_validate(enc, enc) assert not AuthEncoding.pw_validate(enc, 'xxx')
def _pw_encrypt(self, password): """Returns the AuthEncoding encrypted password If 'password' is already encrypted, it is returned as is and not encrypted again. """ if AuthEncoding.is_encrypted(password): return password return AuthEncoding.pw_encrypt(password)
def authenticateCredentials(self, credentials): """ See IAuthenticationPlugin. o We expect the credentials to be those returned by ILoginPasswordExtractionPlugin. """ login = credentials.get('login') password = credentials.get('password') if login is None or password is None: return None # The original implementation does this, which unhelpfully # falls back to giving the login as userid when the login does # not match a user. This means you will seem to login: you # get a message "welcome, you are now logged in". But you are # not actually logged in. #userid = self._login_to_userid.get(login, login) # Instead, we do some more checking ourself. userid = None if '@' not in login or login == login.lower(): userid = self._login_to_userid.get(login) logger.debug("Standard authentication for %s gives userid %s", login, userid) else: # So at this point we have e-mail address as login and it # is not lowercase. We try the given login and then the # lowercase version if nothing is found. userid = self._login_to_userid.get(login) logger.debug("Original case authentication for %s gives " "userid %r", login, userid) if not userid: login = login.lower() userid = self._login_to_userid.get(login) logger.debug("Lower case authentication for %s gives " "userid %r", login, userid) if userid: # Might not be needed, but just in case. credentials['login'] = login if not userid: return None reference = self._user_passwords.get(userid) if reference is None: return None if AuthEncoding.is_encrypted(reference): if AuthEncoding.pw_validate(reference, password): return userid, login # Support previous naive behavior digested = sha.sha(password).hexdigest() if reference == digested: return userid, login return None
def test_reset_password(self): from AccessControl import AuthEncoding member = self._createType(self.layer['portal'], 'dexterity.membrane.member', 'joe') member.email = '*****@*****.**' self.layer['portal'].membrane_tool.reindexObject(member) user_id = get_user_id_for_email(self.layer['portal'], '*****@*****.**') self.layer['portal'].acl_users.userSetPassword(user_id, b'foobar') self.assertTrue(AuthEncoding.is_encrypted(member.password)) scheme_prefix = '{BCRYPT}' self.assertTrue(member.password.startswith(scheme_prefix)) self.assertTrue(AuthEncoding.pw_validate(member.password, b'foobar'))
def setAttempt(self, login, password): "increment attempt count and record date stamp last attempt and IP" root = self.getRootPlugin() count, last, IP, reference = root._login_attempts.get(login, (0, None, '', None)) if reference and AuthEncoding.pw_validate(reference, password): return # we don't count repeating same password in case its correct else: count += 1 IP = self.remote_ip() log.info("user '%s' attempt #%i %s last: %s", login, count, IP, last) last = DateTime() reference = AuthEncoding.pw_encrypt(password) root._login_attempts[login] = (count, last, IP, reference)
def authenticate(self, password, request): passwrd=self._getPassword() result = AuthEncoding.pw_validate(passwrd, password) domains=self.getDomains() if domains: return result and domainSpecMatch(domains, request) return result
def authenticateCredentials(self, credentials): """ See IAuthenticationPlugin. Basically this is like the same method from ZODBUserManager except that we preprocess the password before digesting is, since the migration hashed an already-hashed value. Oh, and we look up the proper plugin by id provided by property. o We expect the credentials to be those returned by ILoginPasswordExtractionPlugin. """ login = credentials.get( 'login' ) password = credentials.get( 'password' ) if login is None or password is None: return None targetname = self.target_id target = getattr(self, targetname) userid = target._login_to_userid.get(login, login) reference = target._user_passwords.get(userid) if reference is None: return None salt = userid[:2] hashed = crypt.crypt(password, salt) if AuthEncoding.pw_validate(reference, hashed): # it would normally be reference, password here return userid, login return None
def _createLDAPPassword(password, encoding='SHA'): """ Create a password string suitable for the userPassword attribute """ encoding = encoding.upper() if encoding in ('SSHA', 'SHA', 'CRYPT'): pwd_str = AuthEncoding.pw_encrypt(password, encoding) elif encoding == 'MD5': m = md5_new(password) pwd_str = '{MD5}' + base64.encodestring(m.digest()) elif encoding == 'CLEAR': pwd_str = password else: pwd_str = AuthEncoding.pw_encrypt(password, 'SSHA') return pwd_str.strip()
def test_legacy_password_validates(self): from AccessControl import AuthEncoding member = self._createType(self.layer['portal'], 'dexterity.membrane.member', 'joe') member.email = '*****@*****.**' self._legacy_set_password(member, b'foobar') self.assertTrue(AuthEncoding.pw_validate(member.password, b'foobar'))
def authenticateCredentials(self, credentials): """ See IAuthenticationPlugin. Basically this is like the same method from ZODBUserManager except that we preprocess the password before digesting is, since the migration hashed an already-hashed value. Oh, and we look up the proper plugin by id provided by property. o We expect the credentials to be those returned by ILoginPasswordExtractionPlugin. """ login = credentials.get('login') password = credentials.get('password') if login is None or password is None: return None targetname = self.target_id target = getattr(self, targetname) userid = target._login_to_userid.get(login, login) reference = target._user_passwords.get(userid) if reference is None: return None salt = userid[:2] hashed = crypt.crypt(password, salt) if AuthEncoding.pw_validate( reference, hashed): # it would normally be reference, password here return userid, login return None
def doChangeUser(self, principal_id, password): """Change a user's password """ if self._user_passwords.get(principal_id) is None: raise RuntimeError("User does not exist: %s" % principal_id) self._user_passwords[principal_id] = AuthEncoding.pw_encrypt(password) notify(CredentialsUpdated(self.getUserById(principal_id), password))
def password(self, password): # When editing, the password field is empty in the browser; do # not do anything then. if password is not None: self.context.password = AuthEncoding.pw_encrypt( safe_encode(password), encoding='BCRYPT' )
def test_createLDAPPassword_crypt(self): try: # Crypt is not available on all platforms encoded = utils._createLDAPPassword(self.pwd, 'crypt') self.assertTrue(encoded.startswith('{CRYPT}')) self.assertTrue(AuthEncoding.pw_validate(encoded, self.pwd)) except ImportError: pass
def setPasswordForUser(self, login, password): """Add password to the list of previously used passwords for a user. """ hashes = self._user_passwords.get(login, []) hash = AuthEncoding.pw_encrypt(password) hashes.append(hash) self._user_passwords[login] = hashes log.info("Password '%s' for user '%s' stored" % (password, login))
def validateSignPassword(self, typed_pass): sign_password = self.getSignPassword() password_matches = AuthEncoding.pw_validate(sign_password, typed_pass) if password_matches: return True return "Password doesn't match"
def updateUserPassword( self, user_id, password ): if self._user_passwords.get( user_id ) is None: raise KeyError, 'Invalid user ID: %s' % user_id if password: digested = AuthEncoding.pw_encrypt( password ) self._user_passwords[ user_id ] = digested
def authenticateCredentials(self, credentials): """ See IAuthenticationPlugin. o We expect the credentials to be those returned by ILoginPasswordExtractionPlugin. """ login = credentials.get('login') password = credentials.get('password') if login is None or password is None: return None # Do we have a link between login and userid? Do NOT fall # back to using the login as userid when there is no match, as # that gives a high chance of seeming to log in successfully, # but in reality failing. userid = self._login_to_userid.get(login) if userid is None: # Someone may be logging in with a userid instead of a # login name and the two are not the same. We could try # turning those around, but really we should just fail. # # userid = login # login = self._userid_to_login.get(userid) # if login is None: # return None return None reference = self._user_passwords.get(userid) if reference is None: return None if AuthEncoding.is_encrypted(reference): if AuthEncoding.pw_validate(reference, password): return userid, login # Support previous naive behavior if isinstance(password, six.text_type): password = password.encode('utf8') digested = sha(password).hexdigest() if reference == digested: return userid, login return None
def updateUserPassword(self, user_id, password): if self._user_passwords.get(user_id) is None: raise KeyError, 'Invalid user ID: %s' % user_id if password: digested = AuthEncoding.pw_encrypt(password) self._user_passwords[user_id] = digested
def authenticateCredentials( self, credentials ): """ See IAuthenticationPlugin. o We expect the credentials to be those returned by ILoginPasswordExtractionPlugin. """ login = credentials.get( 'login' ) password = credentials.get( 'password' ) if login is None or password is None: return None # Do we have a link between login and userid? Do NOT fall # back to using the login as userid when there is no match, as # that gives a high chance of seeming to log in successfully, # but in reality failing. userid = self._login_to_userid.get(login) if userid is None: # Someone may be logging in with a userid instead of a # login name and the two are not the same. We could try # turning those around, but really we should just fail. # # userid = login # login = self._userid_to_login.get(userid) # if login is None: # return None return None reference = self._user_passwords.get(userid) if reference is None: return None if AuthEncoding.is_encrypted( reference ): if AuthEncoding.pw_validate( reference, password ): return userid, login # Support previous naive behavior digested = sha( password ).hexdigest() if reference == digested: return userid, login return None
def isPasswordUsed(self, login, password, history_size=0): """Query password store to see if password has been previously used. """ for hash in self.getPasswordsForUser(login, history_size): if AuthEncoding.pw_validate(hash, password): log.info("Password '%s' for user '%s' not valid (already used)" % (password, login)) return True log.info("Password '%s' for user '%s' valid" % (password, login)) return False
def test_reset_password(self): from AccessControl import AuthEncoding member = self._createType( self.layer['portal'], 'dexterity.membrane.member', 'joe', ) member.email = '*****@*****.**' self.layer['portal'].membrane_tool.reindexObject(member) user_id = get_user_id_for_email( self.layer['portal'], '*****@*****.**', ) self.layer['portal'].acl_users.userSetPassword(user_id, b'foobar') self.assertTrue(AuthEncoding.is_encrypted(member.password)) scheme_prefix = '{BCRYPT}' self.assertTrue(member.password.startswith(scheme_prefix)) self.assertTrue(AuthEncoding.pw_validate(member.password, b'foobar'))
def test_createLDAPPassword_crypt(self): try: # Crypt is not available on all platforms import crypt encoded = utils._createLDAPPassword(self.pwd, 'crypt') self.failUnless(encoded.startswith('{CRYPT}')) self.failUnless(AuthEncoding.pw_validate(encoded, self.pwd)) except ImportError: pass
def test_legacy_password_validates(self): from AccessControl import AuthEncoding member = self._createType( self.layer['portal'], 'dexterity.membrane.member', 'joe', ) member.email = '*****@*****.**' self._legacy_set_password(member, b'foobar') self.assertTrue(AuthEncoding.pw_validate(member.password, b'foobar'))
def _migrate_user( new_user_folder, login, password ): from AccessControl import AuthEncoding if AuthEncoding.is_encrypted( password ): new_user_folder._user_passwords[ login ] = password new_user_folder._login_to_userid[ login ] = login new_user_folder._userid_to_login[ login ] = login else: new_user_folder.addUser( login, login, password )
def addUser(self, user_id, login_name, password): if self._user_passwords.get(user_id) is not None: raise KeyError, 'Duplicate user ID: %s' % user_id if self._login_to_userid.get(login_name) is not None: raise KeyError, 'Duplicate login name: %s' % login_name self._user_passwords[user_id] = AuthEncoding.pw_encrypt(password) self._login_to_userid[login_name] = user_id self._userid_to_login[user_id] = login_name
def addUser( self, user_id, login_name, password ): if self._user_passwords.get( user_id ) is not None: raise KeyError, 'Duplicate user ID: %s' % user_id if self._login_to_userid.get( login_name ) is not None: raise KeyError, 'Duplicate login name: %s' % login_name self._user_passwords[ user_id ] = AuthEncoding.pw_encrypt( password ) self._login_to_userid[ login_name ] = user_id self._userid_to_login[ user_id ] = login_name
def setAttempt(self, login, password): "increment attempt count and record date stamp last attempt and IP" root = self.getRootPlugin() count, last, IP, reference = root._login_attempts.get( login, (0, None, '', None)) if reference and AuthEncoding.pw_validate(reference, password): # we don't count repeating same password in case its correct return if last and ((DateTime() - last) * 24) > self.getResetPeriod(): # set count to 1 following login attempt after reset period count = 1 else: count += 1 IP = self.remote_ip() log.info("user '%s' attempt #%i %s last: %s", login, count, IP, last) last = DateTime() reference = AuthEncoding.pw_encrypt(password) root._login_attempts[login] = (count, last, IP, reference)
def test_getUserWithExtras(self): user = self.suf.getUser('test_user_with_extras') self.failUnless(isinstance(user, User)) self.failUnless(AuthEncoding.pw_validate(user.__, 'password')) self.assertEqual(user.name, 'test_user_with_extras') self.assertEqual(list(user.roles), []) if self.extra_attribute_tests: self.assertEqual(user['extra1'], 'extra1value') self.assertEqual(user['extra2'], 2) # A final check that we get a KeyError # if we go for an extra that isn't there self.assertRaises(KeyError, user.__getitem__, 'extra3')
def test__doChangeUserSamePassword(self): self.suf._doChangeUser( 'test_user', None, ['some','roles'], # roles '', # domains ) user = self.users['test_user'] self.failUnless(AuthEncoding.pw_validate(user.password,'password' )) self.assertEqual(list(user.roles),['some','roles']) self.assertEqual(list(self.suf.getUserNames()),['test_user','test_user_with_extras']) self.assertEqual(list(self.suf.getUser('test_user').roles),['some','roles'])
def test_getUserWithExtras(self): user = self.suf.getUser('test_user_with_extras') self.failUnless(isinstance(user,User)) self.failUnless(AuthEncoding.pw_validate(user.__,'password' )) self.assertEqual(user.name,'test_user_with_extras') self.assertEqual(list(user.roles),[]) if self.extra_attribute_tests: self.assertEqual(user['extra1'],'extra1value') self.assertEqual(user['extra2'],2) # A final check that we get a KeyError # if we go for an extra that isn't there self.assertRaises(KeyError,user.__getitem__,'extra3')
def verifyCredentials(self, credentials): """Returns True is password is authenticated, False if not. """ user = IMembraneUserObject(self.context) if credentials.get("login") != user.getUserName(): # Should never happen, as the code should then never end # up here, but better safe than sorry. return False password_provider = IProvidePasswordsSchema(self.context) if not password_provider: return False return AuthEncoding.pw_validate(password_provider.password, credentials.get("password", ""))
def verifyCredentials(self, credentials): """Returns True is password is authenticated, False if not. """ user = IMembraneUserObject(self.context) if credentials.get('login') != user.getUserName(): # Should never happen, as the code should then never end # up here, but better safe than sorry. return False password_provider = IProvidePasswordsSchema(self.context) if not password_provider: return False return AuthEncoding.pw_validate(password_provider.password, credentials.get('password', ''))
def authenticateCredentials(self, credentials): """ Fulfill AuthenticationPlugin requirements """ acl = self._getUserFolder() login = credentials.get('login', '') password = credentials.get('password', '') if not acl or not login or not password: return (None, None) if login == emergency_user.getUserName() and \ AuthEncoding.pw_validate(emergency_user._getPassword(), password): return (login, login) user = acl.getUser(login) if user is None: return (None, None) elif user and AuthEncoding.pw_validate(user._getPassword(), password): return (user.getId(), login) return (None, None)
def addUser(self, user_id, login_name, password): """Original ZODBUserManager.addUser, modified to check if incoming password is already encypted. This support clean migration from default user source. Should go into PAS. """ if self._user_passwords.get(user_id) is not None: raise KeyError('Duplicate user ID: %s' % user_id) if self._login_to_userid.get(login_name) is not None: raise KeyError('Duplicate login name: %s' % login_name) if not AuthEncoding.is_encrypted(password): password = AuthEncoding.pw_encrypt(password) self._user_passwords[user_id] = password self._login_to_userid[login_name] = user_id self._userid_to_login[user_id] = login_name # enumerateUsers return value has changed view_name = createViewName('enumerateUsers') self.ZCacheable_invalidate(view_name=view_name)
def addUser(self, user_id, login_name, password): """Original ZODBUserManager.addUser, modified to check if incoming password is already encypted. This support clean migration from default user source. Should go into PAS. """ if self._user_passwords.get(user_id) is not None: raise KeyError, 'Duplicate user ID: %s' % user_id if self._login_to_userid.get(login_name) is not None: raise KeyError, 'Duplicate login name: %s' % login_name if not AuthEncoding.is_encrypted(password): password = AuthEncoding.pw_encrypt(password) self._user_passwords[ user_id ] = password self._login_to_userid[ login_name ] = user_id self._userid_to_login[ user_id ] = login_name # enumerateUsers return value has changed view_name = createViewName('enumerateUsers') self.ZCacheable_invalidate(view_name=view_name)
def setAttempt(self, login, password): "increment attempt count and record date stamp last attempt and IP" # TODO: why are the login attempts stored in the root? The usernames aren't unique in the root. root = self.getRootPlugin() count, last, IP, reference = root._login_attempts.get( login, (0, None, '', None)) if reference and AuthEncoding.pw_validate(reference, password): # we don't count repeating same password in case its correct return if last and ((DateTime() - last) * 24) > self.getResetPeriod(): # set count to 1 following login attempt after reset period count = 1 else: count += 1 IP = self.remote_ip() log.info("user '%s' attempt #%i %s last: %s", login, count, IP, last) last = DateTime() reference = AuthEncoding.pw_encrypt(password) root._login_attempts[login] = (count, last, IP, reference)
def testBadPasword(self): pw = 'OK_pa55w0rd \n' for id in AuthEncoding.listSchemes(): enc = AuthEncoding.pw_encrypt(pw, id) assert enc != pw assert not AuthEncoding.pw_validate(enc, 'xxx') assert not AuthEncoding.pw_validate(enc, enc) if id != 'CRYPT': # crypt truncates passwords and would fail this test. assert not AuthEncoding.pw_validate(enc, pw[:-1]) assert not AuthEncoding.pw_validate(enc, pw[1:]) assert AuthEncoding.pw_validate(enc, pw)
def testLongPassword(self): pw = 'Pw' * 2000 for id in AuthEncoding.listSchemes(): enc = AuthEncoding.pw_encrypt(pw, id) assert enc != pw assert AuthEncoding.pw_validate(enc, pw) assert not AuthEncoding.pw_validate(enc, enc) assert not AuthEncoding.pw_validate(enc, 'xxx') if id != 'CRYPT': # crypt truncates passwords and would fail these tests. assert not AuthEncoding.pw_validate(enc, pw[:-2]) assert not AuthEncoding.pw_validate(enc, pw[2:])
def test__doChangeUserSamePassword(self): self.suf._doChangeUser( 'test_user', None, ['some', 'roles'], # roles '', # domains ) user = self.users['test_user'] self.failUnless(AuthEncoding.pw_validate(user.password, 'password')) self.assertEqual(list(user.roles), ['some', 'roles']) self.assertEqual(list(self.suf.getUserNames()), ['test_user', 'test_user_with_extras']) self.assertEqual(list(self.suf.getUser('test_user').roles), ['some', 'roles'])
def testGoodPassword(self): pw = 'good_password' assert len(AuthEncoding.listSchemes()) > 0 # At least one must exist! for id in AuthEncoding.listSchemes(): enc = AuthEncoding.pw_encrypt(pw, id) assert enc != pw assert AuthEncoding.pw_validate(enc, pw) assert AuthEncoding.is_encrypted(enc) assert not AuthEncoding.is_encrypted(pw)
def _migrate_user(pas, login, password, roles): from AccessControl import AuthEncoding if AuthEncoding.is_encrypted(password): pas.users._user_passwords[login] = password pas.users._login_to_userid[login] = login pas.users._userid_to_login[login] = login else: pas.users.addUser(login, login, password) new_user = pas.getUser(login) for role_id in roles: if role_id not in ['Authenticated', 'Anonymous']: pas.roles.assignRoleToPrincipal(role_id, new_user.getId())
def addUser(self, user_id, login_name, password): if self._user_passwords.get(user_id) is not None: raise KeyError, 'Duplicate user ID: %s' % user_id if self._login_to_userid.get(login_name) is not None: raise KeyError, 'Duplicate login name: %s' % login_name self._user_passwords[user_id] = AuthEncoding.pw_encrypt(password) self._login_to_userid[login_name] = user_id self._userid_to_login[user_id] = login_name # enumerateUsers return value has changed view_name = createViewName('enumerateUsers') self.ZCacheable_invalidate(view_name=view_name)
def updateUserPassword(self, user_id, login_name, password): if self._user_passwords.get(user_id) is None: raise KeyError, 'Invalid user ID: %s' % user_id old_login_name = self._userid_to_login[user_id] if old_login_name != login_name: del self._login_to_userid[old_login_name] self._login_to_userid[login_name] = user_id self._userid_to_login[user_id] = login_name if password: digested = AuthEncoding.pw_encrypt(password) self._user_passwords[user_id] = digested
def updateUserPassword( self, user_id, login_name, password ): if self._user_passwords.get( user_id ) is None: raise KeyError, 'Invalid user ID: %s' % user_id old_login_name = self._userid_to_login[ user_id ] if old_login_name != login_name: del self._login_to_userid[ old_login_name ] self._login_to_userid[ login_name ] = user_id self._userid_to_login[ user_id ] = login_name if password: digested = AuthEncoding.pw_encrypt( password ) self._user_passwords[ user_id ] = digested
def test__doAddUser(self): self.suf._doAddUser( 'testname', 'testpassword', ['one','two'], # roles [], # domains ) user = self.users['testname'] self.failUnless(AuthEncoding.pw_validate(user.password,'testpassword' )) self.assertEqual(list(user.roles),['one','two']) # order of names is not ensured names = list(self.suf.getUserNames()) names.sort() self.assertEqual(names,['test_user','test_user_with_extras','testname']) self.assertEqual(list(self.suf.getUser('testname').roles),['one','two'])