NOT Dexter's Lab

Roundcube: come permettere agli utenti di cambiare le loro password

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

Se vi è mai capitato di gestire un server di posta, sono certo che avete investito del tempo ad esaminare Squirrelmail o Horde per permettere ai vostri utenti di accedere alle loro caselle di posta via browser. Entrambe questi prodotti sono oramai stabili e molto maturi, ma la mancanza di un tema accattivante out-of-the-box comincia a farsi sentire nei nostri giorni del web x.0.

Roundcube è un software open source alternativo, non ancora maturo come quelli citati prima, rilasciato sotto licenza GPL che ha una bellissima skin predefinita. Purtroppo, manca ancora di una importantissima caratteristica: la possibilità di far cambiare le password agli utenti in maniera autonoma. Ma è il vostro giorno fortunato: ho scritto una piccola patch per poterlo fare con Roundcube 0.1 (stable).


Il mio codice è basato su quello di polinoma reperibile qui. Basta applicare la patch (questa guida spiega come fare) scaricabile in fondo a questo articolo o seguire le istruzioni di seguito elencate. In ogni caso, bisogna anche modificare manualmente il file program\steps\settings\save_prefs.inc per segnalare a Roundcube come salvare la password nel database.

Passo 1. Modificare program\steps\settings\save_prefs.inc
Vicino la linea 27, c’è un blocco di codice che dichiara un array. Inizia con “$a_user_prefs = array(“. Aggiungi, subito dopo “‘prefer_html’ => isset($_POST['_prefer_html']) ? TRUE : FALSE,“, il codice

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

Adesso cercate “foreach ((array)$CONFIG['dont_override'] as $p)” vicino la linea 39, per aggiungere il blocco che gestirà il salvataggio sul database.

// 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

Se il vostro database non contiene le password in chiaro, ma degli hash, inserite al posto di YourEncryptionFunctionHERE il nome della funzione che utilizzate per crittare le password. Se per esempio state memorizzando hash MD5 delle password e la funzione che utilizzate si chiama md5, metterete quella al posto di YourEncryptionFunctionHERE. Non dimenticate inoltre di cambiare la query in mysql_query per adeguarla alla struttura del vostro database.

Passo 2. Modificare program\steps\settings\func.inc
Vicino la linea 200, cercate “$out .= “\n</table>$form_end”;“. Prima di questa linea, aggiungete:

// 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

Se avete eseguito correttamente le mie istruzioni, dovrebbe funzionare (si spera!). Come sempre, se avete problemi, postate pure un commento e vedrò quel che posso fare per aiutarvi.

Patch per Roundcube 0.1 (Stable)

:, , ,

  • http://missiomariae.net 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

  • http://www.a2p.it 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

  • http://www.a2p.it 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

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!