[dev] Horde :: Remember Username patch for Login

Joel Vandal jvandal at infoteck.qc.ca
Fri Apr 23 08:01:24 PDT 2004


Hi,

I hope this time the patch will be ok :D

> I'm really not sure if I want to see such a functionality in Horde but I
> know that people will love it, and if Horde is only used for a forum or
> some such it makes sense.

> A few comments though:
> - It MUST be configurable, that is being turned off in the configuration

Configurable ? I've move all to preference so an user can set if they want
to remember user or both user and pass.

> - It should be a "remember me" feature, that is not only remembering the
> user and/or password, but automatically log the user in with these
> credentials.

Also add a preference if the user want to automatically sign up.
When a user have set to "remember both user/pass" or "Auto Signup" and click
on "Logout", the password will be cleared.

> - Please provide patches as unified diffs.

Ok :) cvs diff -u ...

-- 
Joel Vandal                                    Infoteck Internet
http://www.infoteck.qc.ca            Tel.  819-370-3232
jvandal at infoteck.qc.ca                 Fax. 819-370-3624
-------------- next part --------------
Index: login.php
===================================================================
RCS file: /repository/horde/login.php,v
retrieving revision 2.157
diff -u -r2.157 login.php
--- login.php 8 Apr 2004 21:19:20 -0000 2.157
+++ login.php 23 Apr 2004 14:41:33 -0000
@@ -28,8 +28,19 @@
 $logout_reason = $auth->getLogoutReason();
 $url_param = Util::getFormData('url');
 
+if (isset($_COOKIE['horde_language'])) {
+    NLS::setLang($_COOKIE['horde_language']);
+}
+
 if ($logout_reason) {
     $login_screen = $auth->_getLoginScreen();
+
+    if (!$prefs->getValue('autologin')) {
+        setcookie('horde_autologin', '', time() - 3600);
+    }
+    
+    setcookie('horde_pass', '', time() - 3600);
+    
     if (Util::removeParameter($login_screen, array('url', 'nocache')) !=
         Util::removeParameter(Horde::url(Horde::selfUrl(), true), array('url', 'nocache'))) {
         $url = Auth::addLogoutParameters($login_screen);
@@ -65,13 +76,44 @@
     $_GET['new_lang'] = $language;
 }
 
-if (isset($_POST['horde_user']) && isset($_POST['horde_pass'])) {
+// Check for autologin auth.
+if (isset($_COOKIE['horde_autologin']) && isset($_COOKIE['horde_user']) && isset($_COOKIE['horde_pass'])) {
+    if (!isset($_POST['horde_user']) && !Auth::getAuth() && !isset($_GET['reason']) &&
+        $auth->authenticate($_COOKIE['horde_user'],
+                            array('password' => $_COOKIE['horde_pass']))) {
+        
+        header('Location: ' . Horde::applicationUrl('index.php'));
+        exit;
+    }
+}
 
+if (isset($_POST['horde_user']) && isset($_POST['horde_pass'])) {
+    
     /* Destroy any existing session on login and make sure to use a
      * new session ID, to avoid session fixation issues. */
     Horde::getCleanSession();
+    
     if ($auth->authenticate(Util::getPost('horde_user'),
                             array('password' => Util::getPost('horde_pass')))) {
+
+
+        if ($prefs->getValue('autologin')) {
+            setcookie('horde_autologin', 1, mktime(0, 0, 0, 1, 1, 2015));
+        }
+        
+        $login = $prefs->getValue('login');
+        
+        if ($login > 0) {
+            
+            setcookie('horde_user', Util::getPost('horde_user'), mktime(0, 0, 0, 1, 1, 2015));
+            setcookie('horde_language', Util::getPost('new_lang'), mktime(0, 0, 0, 1, 1, 2015));
+            
+            if ($login == 2) {
+                setcookie('horde_pass', Util::getPost('horde_pass'), mktime(0, 0, 0, 1, 1, 2015));
+            }
+            
+        }
+
         $entry = sprintf('Login success for %s [%s] to Horde',
                          Auth::getAuth(), $_SERVER['REMOTE_ADDR']);
         Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_INFO);
@@ -142,7 +184,11 @@
     $_SESSION['horde_language'] = NLS::select();
     $langs = '<select name="new_lang" onchange="selectLang()">';
     foreach ($nls['languages'] as $key => $val) {
-        $sel = ($key == $_SESSION['horde_language']) ? ' selected="selected"' : '';
+        if (isset($_COOKIE['horde_language'])) {
+            $sel = ($key == $_COOKIE['horde_language']) ? ' selected="selected"' : '';          
+        } else {
+            $sel = ($key == $_SESSION['horde_language']) ? ' selected="selected"' : '';
+        }
         $langs .= "<option value=\"$key\"$sel>$val</option>";
     }
     $langs .= '</select>';
-------------- next part --------------
Index: prefs.php.dist
===================================================================
RCS file: /repository/horde/config/prefs.php.dist,v
retrieving revision 1.58
diff -u -r1.58 prefs.php.dist
--- prefs.php.dist 3 Mar 2004 10:37:22 -0000 1.58
+++ prefs.php.dist 23 Apr 2004 14:47:42 -0000
@@ -90,6 +90,13 @@
     'members' => array('imsp_auth_user', 'imsp_auth_pass')
 );
 
+$prefGroups['login'] = array(
+    'column' => _("Your Information"),
+    'label' => _("Login Information"),
+    'desc' => sprintf(_("Choose which of the login information that %s should remember."), $GLOBALS['registry']->getParam('name', 'horde')),
+    'members' => array('autologin', 'login')
+);
+
 // user language
 $_prefs['language'] = array(
     'value' => '',
@@ -307,3 +314,24 @@
     'type' => 'password',
     'desc' => _("Alternate IMSP Password")
 );
+
+
+$_prefs['login'] = array(
+    'value' => 1,
+    'locked' => false,
+    'shared' => false,
+    'type' => 'enum',
+    'enum' => array(0 => _("None"),
+                    1 => _("Username"),
+                    2 => _("Username and Password")),
+    'desc' => _("Login information to remember:")
+);
+
+$_prefs['autologin'] = array(
+    'value' => 0,
+    'locked' => false,
+    'shared' => true,
+    'type' => 'checkbox',
+    'desc' => _("Sign me in automatically")
+);
+                         
-------------- next part --------------
Index: login.inc
===================================================================
RCS file: /repository/horde/templates/login/login.inc,v
retrieving revision 2.51
diff -u -r2.51 login.inc
--- login.inc 30 Mar 2004 17:50:51 -0000 2.51
+++ login.inc 23 Apr 2004 14:57:50 -0000
@@ -69,12 +69,20 @@
 
 <tr>
     <td align="right" class="light"><b><?php echo _("Username") ?></b>&nbsp;</td>
+    <?php if (isset($_COOKIE['horde_user'])): ?>
+    <td align="left"><input class="fixed" type="text" name="horde_user" value="<?php echo $_COOKIE['horde_user'] ?>" /></td>
+    <?php else: ?>
     <td align="left"><input class="fixed" type="text" name="horde_user" value="<?php echo Util::getFormData('horde_user') ?>" /></td>
+    <?php endif; ?>
 </tr>
 
 <tr>
     <td align="right" class="light"><b><?php echo _("Password") ?></b>&nbsp;</td>
+    <?php if (isset($_COOKIE['horde_pass'])): ?>
+    <td align="left"><input class="fixed" type="password" name="horde_pass" value="<?php echo $_COOKIE['horde_pass'] ?>" /></td>
+    <?php else: ?>
     <td align="left"><input class="fixed" type="password" name="horde_pass" value="" /></td>
+    <?php endif; ?>
 </tr>
 
 <?php if (!$prefs->isLocked('language')): ?>


More information about the dev mailing list