Index: trunk/lib/Prefs.inc.php
===================================================================
--- trunk/lib/Prefs.inc.php	(revision 461)
+++ trunk/lib/Prefs.inc.php	(revision 462)
@@ -4,5 +4,5 @@
  * For details visit the project site: <http://trac.strangecode.com/codebase/>
  * Copyright 2001-2012 Strangecode, LLC
- * 
+ *
  * This file is part of The Strangecode Codebase.
  *
@@ -11,10 +11,10 @@
  * Free Software Foundation, either version 3 of the License, or (at your option)
  * any later version.
- * 
+ *
  * The Strangecode Codebase is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  * details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along with
  * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
@@ -24,10 +24,10 @@
  * Prefs.inc.php
  *
- * Prefs provides an API for saving arbitrary values in a user's session. 
+ * Prefs provides an API for saving arbitrary values in a user's session.
  * Session prefs can be stored into a database with the optional save() and load() methods.
  *
  * @author  Quinn Comendant <quinn@strangecode.com>
  * @version 2.1
- * 
+ *
  * Example of use:
 ---------------------------------------------------------------------
@@ -59,14 +59,14 @@
     // Configuration parameters for this object.
     var $_params = array(
-        
+
         // Enable database storage. If this is false, all prefs will live only as long as the session.
         'persistent' => false,
-        
+
         // The current user_id for which to load/save persistent preferences.
         'user_id' => null,
-        
+
         // How long before we force a reload of the persistent prefs data? 3600 = once every hour.
         'load_timeout' => 3600,
-        
+
         // Name of database table to store persistent prefs.
         'db_table' => 'pref_tbl',
@@ -85,5 +85,5 @@
 
         $this->_ns = $namespace;
-        
+
         // Initialized the prefs array.
         if (!isset($_SESSION['_prefs'][$this->_ns])) {
@@ -160,5 +160,5 @@
     {
 		$app =& App::getInstance();
-    
+
         if (isset($this->_params[$param])) {
             return $this->_params[$param];
@@ -170,9 +170,9 @@
 
     /**
-     * Sets the default values for preferences. If a preference is not explicitly 
+     * Sets the default values for preferences. If a preference is not explicitly
      * set, the value set here will be used. Can be called multiple times to merge additional
      * defaults together.
      *
-     * @param  array $defaults  Array of key-value pairs 
+     * @param  array $defaults  Array of key-value pairs
      */
     function setDefaults($defaults)
@@ -200,11 +200,13 @@
             return false;
         }
-        
-        // Set a persistent preference if...
+
+        // Set a saved preference if...
         // - there isn't a default.
-        // - the new value is different than the default
-        // - there is a previously existing persistent key.
-        if (!isset($_SESSION['_prefs'][$this->_ns]['defaults'][$key]) || $_SESSION['_prefs'][$this->_ns]['defaults'][$key] != $val || isset($_SESSION['_prefs'][$this->_ns]['persistent'][$key])) {
-            $_SESSION['_prefs'][$this->_ns]['persistent'][$key] = $val;            
+        // - or the new value is different than the default
+        // - or there is a previously existing saved key.
+        if (!isset($_SESSION['_prefs'][$this->_ns]['defaults'][$key])
+        || $_SESSION['_prefs'][$this->_ns]['defaults'][$key] != $val
+        || isset($_SESSION['_prefs'][$this->_ns]['saved'][$key])) {
+            $_SESSION['_prefs'][$this->_ns]['saved'][$key] = $val;
             $app->logMsg(sprintf('Setting preference %s => %s', $key, truncate(getDump($val, true), 128, 'end')), LOG_DEBUG, __FILE__, __LINE__);
         } else {
@@ -214,5 +216,5 @@
 
     /**
-     * Returns the value of the requested preference. Persistent values take precedence, but if none is set
+     * Returns the value of the requested preference. Saved values take precedence, but if none is set
      * a default value is returned, or if not that, null.
      *
@@ -224,7 +226,7 @@
     {
         $app =& App::getInstance();
-        if (isset($_SESSION['_prefs'][$this->_ns]['persistent']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['persistent'])) {
-            $app->logMsg(sprintf('Found %s in persistent', $key), LOG_DEBUG, __FILE__, __LINE__);
-            return $_SESSION['_prefs'][$this->_ns]['persistent'][$key];
+        if (isset($_SESSION['_prefs'][$this->_ns]['saved']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved'])) {
+            $app->logMsg(sprintf('Found %s in saved', $key), LOG_DEBUG, __FILE__, __LINE__);
+            return $_SESSION['_prefs'][$this->_ns]['saved'][$key];
         } else if (isset($_SESSION['_prefs'][$this->_ns]['defaults']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults'])) {
             $app->logMsg(sprintf('Found %s in defaults', $key), LOG_DEBUG, __FILE__, __LINE__);
@@ -244,9 +246,9 @@
     function exists($key)
     {
-        return array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['persistent']);
-    }
-
-    /**
-     * Clear a set preference value. This will also remove the value from the database. 
+        return array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']);
+    }
+
+    /**
+     * Clear a set preference value. This will also remove the value from the database.
      *
      * @param string $key       The name of the preference to delete.
@@ -254,9 +256,9 @@
     function delete($key)
     {
-        unset($_SESSION['_prefs'][$this->_ns]['persistent'][$key]);
-    }
-
-    /**
-     * Resets the $_SESSION cache. This should be executed with the same consideration 
+        unset($_SESSION['_prefs'][$this->_ns]['saved'][$key]);
+    }
+
+    /**
+     * Resets the $_SESSION cache. This should be executed with the same consideration
      * as $auth->clear(), such as when logging out.
      */
@@ -269,5 +271,5 @@
                 'load_datetime' => '1970-01-01',
                 'defaults' => array(),
-                'persistent' => array(),
+                'saved' => array(),
             );
             break;
@@ -277,10 +279,10 @@
             break;
 
-        case 'persistent' :
-            $_SESSION['_prefs'][$this->_ns]['persistent'] = array();
+        case 'saved' :
+            $_SESSION['_prefs'][$this->_ns]['saved'] = array();
             break;
         }
     }
-    
+
     /*
     * Retrieves all prefs from the database and stores them in the $_SESSION.
@@ -297,5 +299,5 @@
         $app =& App::getInstance();
 		$db =& DB::getInstance();
-		
+
 		// Skip this method if not using the db.
 		if (true !== $this->getParam('persistent')) {
@@ -315,8 +317,8 @@
             return false;
         }
-        
+
         // Clear existing cache.
-        $this->clear('persistent');
-        
+        $this->clear('saved');
+
         // Retrieve all prefs for this user and namespace.
 		$qid = $db->query("
@@ -328,20 +330,20 @@
 		");
 		while (list($key, $val) = mysql_fetch_row($qid)) {
-            $_SESSION['_prefs'][$this->_ns]['persistent'][$key] = unserialize($val);
+            $_SESSION['_prefs'][$this->_ns]['saved'][$key] = unserialize($val);
 		}
-		
+
 		$app->logMsg(sprintf('Loaded %s prefs from database.', mysql_num_rows($qid)), LOG_DEBUG, __FILE__, __LINE__);
-		
+
 		// Data loaded only once per session.
 		$_SESSION['_prefs'][$this->_ns]['loaded'] = true;
         $_SESSION['_prefs'][$this->_ns]['load_datetime'] = date('Y-m-d H:i:s');
-		
+
 		return true;
     }
-    
+
     /*
     * Returns true if the prefs had been loaded from the database into the $_SESSION recently.
     * This function is simply a check so the database isn't access every page load.
-    * 
+    *
     * @access   private
     * @return   bool    True if prefs are loaded.
@@ -354,5 +356,5 @@
         if (isset($_SESSION['_prefs'][$this->_ns]['load_datetime'])
         && strtotime($_SESSION['_prefs'][$this->_ns]['load_datetime']) > time() - $this->getParam('load_timeout')
-        && isset($_SESSION['_prefs'][$this->_ns]['loaded']) 
+        && isset($_SESSION['_prefs'][$this->_ns]['loaded'])
         && true === $_SESSION['_prefs'][$this->_ns]['loaded']) {
             return true;
@@ -361,5 +363,5 @@
         }
     }
-    
+
     /*
     * Saves all prefs stored in the $_SESSION into the database.
@@ -375,10 +377,10 @@
         $app =& App::getInstance();
 		$db =& DB::getInstance();
-		
+
 		// Skip this method if not using the db.
 		if (true !== $this->getParam('persistent')) {
 		    return true;
 		}
-        
+
         // User_id must not be empty.
         if ('' == $this->getParam('user_id')) {
@@ -389,5 +391,5 @@
         $this->initDB();
 
-        if (isset($_SESSION['_prefs'][$this->_ns]['persistent']) && is_array($_SESSION['_prefs'][$this->_ns]['persistent']) && !empty($_SESSION['_prefs'][$this->_ns]['persistent'])) {
+        if (isset($_SESSION['_prefs'][$this->_ns]['saved']) && is_array($_SESSION['_prefs'][$this->_ns]['saved']) && !empty($_SESSION['_prefs'][$this->_ns]['saved'])) {
             // Delete old prefs from database.
             $db->query("
@@ -396,12 +398,12 @@
     		    AND pref_namespace = '" . $db->escapeString($this->_ns) . "'
             ");
-            
+
             // Insert new prefs.
             $insert_values = array();
-            foreach ($_SESSION['_prefs'][$this->_ns]['persistent'] as $key => $val) {
-                $insert_values[] = sprintf("('%s', '%s', '%s', '%s')", 
-                    $db->escapeString($this->getParam('user_id')), 
-                    $db->escapeString($this->_ns), 
-                    $db->escapeString($key), 
+            foreach ($_SESSION['_prefs'][$this->_ns]['saved'] as $key => $val) {
+                $insert_values[] = sprintf("('%s', '%s', '%s', '%s')",
+                    $db->escapeString($this->getParam('user_id')),
+                    $db->escapeString($this->_ns),
+                    $db->escapeString($key),
                     $db->escapeString(serialize($val))
                 );
@@ -409,13 +411,13 @@
             // TODO: after MySQL 5.0.23 is released this query could benefit from INSERT DELAYED.
             $db->query("
-                INSERT INTO " . $db->escapeString($this->getParam('db_table')) . " 
+                INSERT INTO " . $db->escapeString($this->getParam('db_table')) . "
                 (user_id, pref_namespace, pref_key, pref_value)
                 VALUES " . join(', ', $insert_values) . "
             ");
-            
+
             $app->logMsg(sprintf('Saved %s prefs to database.', sizeof($insert_values)), LOG_DEBUG, __FILE__, __LINE__);
             return true;
         }
-        
+
         return false;
     }
Index: trunk/services/login.php
===================================================================
--- trunk/services/login.php	(revision 461)
+++ trunk/services/login.php	(revision 462)
@@ -4,5 +4,5 @@
  * For details visit the project site: <http://trac.strangecode.com/codebase/>
  * Copyright 2001-2012 Strangecode, LLC
- * 
+ *
  * This file is part of The Strangecode Codebase.
  *
@@ -11,10 +11,10 @@
  * Free Software Foundation, either version 3 of the License, or (at your option)
  * any later version.
- * 
+ *
  * The Strangecode Codebase is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  * details.
- * 
+ *
  * You should have received a copy of the GNU General Public License along with
  * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
@@ -32,5 +32,13 @@
 $app->sslOn();
 
-$frm['username'] = getFormdata('username');
+require_once 'codebase/lib/Prefs.inc.php';
+$login_prefs = new Prefs('login');
+$login_prefs->setDefaults(array('username' => ''));
+
+if ('' != $login_prefs->get('username')) {
+    $frm['remember_me'] = '1';
+}
+
+$frm['username'] = getFormdata('username', $login_prefs->get('username'));
 $frm['password'] = getFormdata('password');
 
@@ -39,4 +47,9 @@
 
     if ($auth->login($frm['username'], $frm['password'])) {
+        if (getFormData('remember_me')) {
+            $login_prefs->set('username', getFormData('username'));
+        } else {
+            $login_prefs->set('username', '');
+        }
         $app->raiseMsg(_("You are now logged in."), MSG_SUCCESS, __FILE__, __LINE__);
         $app->dieBoomerangURL('login');
Index: trunk/services/templates/login_form.ihtml
===================================================================
--- trunk/services/templates/login_form.ihtml	(revision 461)
+++ trunk/services/templates/login_form.ihtml	(revision 462)
@@ -17,4 +17,10 @@
         </td>
     </tr>
+    <tr class="sc-form-row">
+        <td class="sc-right">&nbsp;</td>
+        <td>
+            <label class="sc-label-secondary"><input type="checkbox" name="remember_me" id="remember_me" value="1"<?php frmChecked($frm['remember_me']) ?> /> <?php echo _("Remember my username"); ?></label>
+        </td>
+    </tr>
     <tr>
         <td>&nbsp;</td>
@@ -23,2 +29,13 @@
 </table>
 </form>
+<script type="text/javascript" charset="utf-8">
+/* <![CDATA[ */
+$(document).ready(function() {
+    if ($('input[name="username"]').val() != '') {
+        $('input[name="password"]').focus();
+    } else {
+        $('input[name="username"]').focus();
+    }
+});
+/* ]]> */
+</script>
