4 * Poppassd change password backend
6 * @author Seth Randall <sethr@missoulafcu.org>
9 * @subpackage change_password
17 * Set the address of the server your poppass daemon runs on.
18 * If it's the same as your imap server, you can leave it blank
20 global $poppassd_server;
22 $poppassd_server = '';
25 * Define here the name of your password changing function.
27 global $squirrelmail_plugin_hooks;
28 $squirrelmail_plugin_hooks['change_password_dochange']['poppassd'] = 'cpw_poppassd_dochange';
29 $squirrelmail_plugin_hooks['change_password_init']['template'] = 'cpw_poppassd_init';
33 * Use this function to do any backend-specific initialization,
34 * e.g. checking requirements, before the password change form
35 * is displayed to the user.
37 function cpw_poppassd_init() {
41 * This is the function that is specific to your backend. It takes
42 * the current password (as supplied by the user) and the desired
43 * new password. It will return an array of messages. If everything
44 * was successful, the array will be empty. Else, it will contain
45 * the errormessage(s).
46 * Constants to be used for these messages:
47 * CPW_CURRENT_NOMATCH -> "Your current password is not correct."
48 * CPW_INVALID_PW -> "Your new password contains invalid characters."
50 * @param array data The username/currentpw/newpw data.
51 * @return array Array of error messages.
53 function cpw_poppassd_dochange($data) {
54 // unfortunately, we can only pass one parameter to a hook function,
55 // so we have to pass it as an array.
56 $username = $data['username'];
57 $curpw = $data['curpw'];
58 $newpw = $data['newpw'];
62 // your code here to change the password for $username from
63 // $currentpw into $newpw.
64 $msgs = cpw_poppassd_go($username, $curpw, $newpw, 0);
69 function cpw_poppassd_closeport($pop_socket, &$messages, $debug = 0) {
71 array_push($messages, _("Closing Connection"));
73 fputs($pop_socket, "quit\r\n");
77 function cpw_poppassd_readfb($pop_socket, &$result, &$messages, $debug = 0) {
81 if (!feof($pop_socket)) {
82 $strResp = fgets($pop_socket, 1024);
83 $result = substr(trim($strResp), 0, 3); // 200, 500
84 if(!preg_match('/^[23]\d\d/', $result) ||
$debug) {
85 $messages[] = "--> $strResp";
90 function cpw_poppassd_go($username, $old_pw, $new_pw, $debug = 0) {
91 global $poppassd_server;
92 global $imapServerAddress;
94 if($poppassd_server == '') {
95 $poppassd_server = $imapServerAddress;
101 $messages[] = _("Connecting to Password Server");
103 $pop_socket = fsockopen($poppassd_server, 106, $errno, $errstr);
105 $messages[] = _("ERROR") . ': ' . "$errstr ($errno)";
109 cpw_poppassd_readfb($pop_socket, $result, $messages, $debug);
110 if(!preg_match('/^2\d\d/', $result) ) {
111 cpw_poppassd_closeport($pop_socket, $messages, $debug);
115 fputs($pop_socket, "user $username\r\n");
116 cpw_poppassd_readfb($pop_socket, $result, $messages, $debug);
117 if(!preg_match('/^[23]\d\d/', $result) ) {
118 cpw_poppassd_closeport($pop_socket, $messages, $debug);
122 fputs($pop_socket, "pass $old_pw\r\n");
123 cpw_poppassd_readfb($pop_socket, $result, $messages, $debug);
124 if(!preg_match('/^[23]\d\d/', $result) ) {
125 cpw_poppassd_closeport($pop_socket, $messages, $debug);
129 fputs($pop_socket, "newpass $new_pw\r\n");
130 cpw_poppassd_readfb($pop_socket, $result, $messages, $debug);
131 cpw_poppassd_closeport($pop_socket, $messages, $debug);
132 if(!preg_match('/^2\d\d/', $result) ) {