NOT Dexter's Lab

Roundcube: allow users to change their own passwords

by on Mar.16, 2008, under Tips and Tricks

If you are running a mail server, I’m pretty sure you’ve invested some time in testing Squirrelmail or Horde in order to provide your users a web access to their emails. Both of them are rock solid, but the lack of a good looking out-of-the-box UI is starting to weight more and more in our web x.0 days.

Roundcube is an alternative, not as mature as the aforementioned, open source software released under GPL license which comes with an awesome default skin. Sadly, it still misses one important thing: the control to make user able to change their own password. But that’s your lucky day: I made a small patch to allow this in Roundcube 0.1 (stable).

My work is based on polinoma’s code found here. You need to apply the patch file (check here if you don’t know how to) which is found at the end of this article or follow the instructions below. Either way, you need to tweak the program\steps\settings\save_prefs.inc file to tell Roundcube how your password is stored in the database.

Step 1. Modifying program\steps\settings\save_prefs.inc
Aproximately near line 27, there is a block where an array is declared. It starts with “$a_user_prefs = array(“. Just add the following line under the “‘prefer_html’ => isset($_POST['_prefer_html']) ? TRUE : FALSE,” line

// Password MOD
'password'  => isset($_POST['_password']) ? TRUE : FALSE,
// End Password MOD

Now after the “foreach ((array)$CONFIG['dont_override'] as $p)” near line 39, add the block which handles password saving to DB

// Password MOD
if (isset($_POST['_password']))
{
$tmpEncPass = YourEncryptionFunctionHERE($_POST['_password'], "");

mysql_query("UPDATE CCC.TableWithPasswordHERE SET password = '".$tmpEncPass."' WHERE username = '".$_SESSION['username']."'")
or die(mysql_error());

$_SESSION['password'] = encrypt_passwd($_POST['_password']);
}
// End Password MOD

In case your database holds encrypted user passwords, put the name of the hashing function in place of YourEncryptionFunctionHERE. If you are storing MD5 hashes of the password in your database and the hashing function you use is md5, you would be writing that instead of YourEncryptionFunctionHERE. Don’t forget to change the query in mysql_query to make it work with your database.

Step 2. Modifying program\steps\settings\func.inc
Near line 200, look for “$out .= “\n</table>$form_end”;“. Before this line, add the following block:

// Password MOD
$field_id = 'rcmfd_password';
$input_password = new textfield(array('name' => '_password', 'id' => $field_id, 'size' => 20));
$out .= sprintf("<tr><td class=\"title\"><label for=\"%s\">%s</label></td><td>%s (empty = unchanged)</td></tr>\n",
$field_id,
rep_specialchars_output(rcube_label('password')),
$input_password->show();
// End Password MOD

If you followed my instructions, it should already be working (hopefully). As usual, if you have any trouble feel free to ask for help by writing a comment!

Patch file for Roundcube 0.1 (Stable)

:, , ,

4 Comments for this entry

  • Martin

    Thanks for this MOD, I am new to RoundCube and I wanted to know ehere you get these:

    1. YourEncryptionFunctionHERE
    2. UPDATE CCC.TableWithPasswordHERE SET password

    Thanks

  • Alessio Placitelli

    You have to replace YourEncryptionFunctionHERE with the name of the encryption function you are using to store user passwords in your database.

    The second line pretty much depends on the structure of the previously mentioned database.

    What email server are you using? If you are using Postfix, then you problably need and MD5 function in place of YourEncryptionFunctionHERE.

  • Martin

    Thanks for the reply. I found out through research that our mail server uses MD5 since the password generated 32 hex digits.

    So if I will enter these infos, correct me if I am wrong, please, I am new to this:

    1. $tmpEncPass = MD5($_POST['_password'], “”);
    2. mysql_query(“UPDATE CCC.users.MYROUNDCUBEDATABASEPASSWORD SET password = ‘”.$tmpEncPass.”‘ WHERE username = ‘”.$_SESSION['username'].”‘”)

    I will really be grateful if you can help me with this. Thanks.

    Martin

  • Alessio Placitelli

    Yes, more or less :)

    1. md5 function should be lowercase (check http://www.php.net/md5 ), and takes one parameter (the second one is optional and should be false to output a 32 hex digits string). So: $tmpEncPass = md5($_POST[’_password’]);

    2. mysql_query(”UPDATE CCC.users SET password = ‘”.$tmpEncPass.”‘ WHERE username = ‘”.$_SESSION[’username’].”‘”) in that line of code, you should replace CCC with the name of the database containing the table “users”.

    Then it should work ! Let me know

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!