Index: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_authentication.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_authentication.py	(revision 9332)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_authentication.py	(revision 9334)
@@ -17,4 +17,5 @@
 ##
 import unittest
+from datetime import datetime, timedelta
 from zope.authentication.interfaces import IAuthentication
 from zope.component import provideUtility, queryUtility, getGlobalSiteManager
@@ -66,4 +67,25 @@
     phone = None
     suspended = False
+    temp_password_minutes = 10
+
+    def setTempPassword(self, user, password):
+        passwordmanager = queryUtility(IPasswordManager, 'SSHA')
+        self.temp_password = {}
+        self.temp_password[
+            'password'] = passwordmanager.encodePassword(password)
+        self.temp_password['user'] = user
+        self.temp_password['timestamp'] = datetime.utcnow()
+
+    def getTempPassword(self):
+        temp_password_dict = getattr(self, 'temp_password', None)
+        if temp_password_dict is not None:
+            delta = timedelta(minutes=self.temp_password_minutes)
+            now = datetime.utcnow()
+            if now < temp_password_dict.get('timestamp') + delta:
+                return temp_password_dict.get('password')
+            else:
+                # Unset temporary password if expired
+                self.temp_password = None
+        return None
 
 
@@ -138,4 +160,27 @@
         return
 
+    def test_check_temp_password(self):
+        # make sure that, if a temp password is set,
+        # this password is used for authentication
+        self.account.setPassword('secret')
+        self.fake_stud.setTempPassword(user='beate', password='temp_secret')
+        result1 = self.account.checkPassword('secret')
+        result2 = self.account.checkPassword(None)
+        result3 = self.account.checkPassword('nonsense')
+        result4 = self.account.checkPassword('temp_secret')
+        self.assertEqual(result1, False)
+        self.assertEqual(result2, False)
+        self.assertEqual(result3, False)
+        self.assertEqual(result4, True)
+        # if the temp password is expired, the original password
+        # is used again
+        delta = timedelta(minutes=11)
+        self.fake_stud.temp_password['timestamp'] = datetime.utcnow() - delta
+        result5 = self.account.checkPassword('temp_secret')
+        result6 = self.account.checkPassword('secret')
+        self.assertEqual(result5, False)
+        self.assertEqual(result6, True)
+        return
+
     def test_check_unset_password(self):
         # empty and unset passwords do not match anything
Index: main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py
===================================================================
--- main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py	(revision 9332)
+++ main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_browser.py	(revision 9334)
@@ -1183,5 +1183,5 @@
         return
 
-    def test_student_access(self):
+    def test_student_login(self):
         # Student cant login if their password is not set
         self.student.password = None
@@ -1195,5 +1195,4 @@
         IUserAccount(
             self.app['students'][self.student_id]).setPassword('spwd')
-        IWorkflowInfo(self.student).fireTransition('admit')
         # Students can't login if their account is suspended/deactivated
         self.student.suspended = True
@@ -1202,10 +1201,54 @@
         self.browser.getControl(name="form.password").value = 'spwd'
         self.browser.getControl("Login").click()
-        self.assertTrue(
-            'Your account has been deactivated.' in self.browser.contents)
+        self.assertMatches(
+            '...Your account has been deactivated...', self.browser.contents)
         self.student.suspended = False
+        # Students can't login if a temporary password has been set and
+        # is not expired
+        self.app['students'][self.student_id].setTempPassword(
+            'anybody', 'temp_spwd')
+        self.browser.open(self.login_path)
+        self.browser.getControl(name="form.login").value = self.student_id
+        self.browser.getControl(name="form.password").value = 'spwd'
         self.browser.getControl("Login").click()
-        self.assertTrue(
-            'You logged in.' in self.browser.contents)
+        self.assertMatches(
+            '...Your account has been temporarily deactivated...',
+            self.browser.contents)
+        # The student can login with the temporary password
+        self.browser.open(self.login_path)
+        self.browser.getControl(name="form.login").value = self.student_id
+        self.browser.getControl(name="form.password").value = 'temp_spwd'
+        self.browser.getControl("Login").click()
+        self.assertMatches(
+            '...You logged in...', self.browser.contents)
+        # Student can view the base data
+        self.browser.open(self.student_path)
+        self.assertEqual(self.browser.headers['Status'], '200 Ok')
+        self.assertEqual(self.browser.url, self.student_path)
+        # When the password expires ...
+        delta = timedelta(minutes=11)
+        self.app['students'][self.student_id].temp_password[
+            'timestamp'] = datetime.utcnow() - delta
+        self.app['students'][self.student_id]._p_changed = True
+        # ... the student will be automatically logged out
+        self.assertRaises(
+            Unauthorized, self.browser.open, self.student_path)
+        # Then the student can login with the original password
+        self.browser.open(self.login_path)
+        self.browser.getControl(name="form.login").value = self.student_id
+        self.browser.getControl(name="form.password").value = 'spwd'
+        self.browser.getControl("Login").click()
+        self.assertMatches(
+            '...You logged in...', self.browser.contents)
+
+    def test_student_access(self):
+        # Student cant login if their password is not set
+        IWorkflowInfo(self.student).fireTransition('admit')
+        self.browser.open(self.login_path)
+        self.browser.getControl(name="form.login").value = self.student_id
+        self.browser.getControl(name="form.password").value = 'spwd'
+        self.browser.getControl("Login").click()
+        self.assertMatches(
+            '...You logged in...', self.browser.contents)
         # Admitted student can upload a passport picture
         self.browser.open(self.student_path + '/change_portrait')
