From e2afce407378c6496a1bbac0b178d2ca54c9933e Mon Sep 17 00:00:00 2001 From: Miles Lott Date: Mon, 26 Mar 2001 21:36:32 +0000 Subject: [PATCH] Fix account_id use in update_lastlogin to use get_account_id; formatting --- phpgwapi/inc/class.auth_http.inc.php | 35 ++++++------- phpgwapi/inc/class.auth_ldap.inc.php | 76 ++++++++++++++-------------- phpgwapi/inc/class.auth_mail.inc.php | 75 ++++++++++++++------------- phpgwapi/inc/class.auth_sql.inc.php | 73 +++++++++++++------------- 4 files changed, 134 insertions(+), 125 deletions(-) diff --git a/phpgwapi/inc/class.auth_http.inc.php b/phpgwapi/inc/class.auth_http.inc.php index 847ced7e3c..0ee0e5abdb 100644 --- a/phpgwapi/inc/class.auth_http.inc.php +++ b/phpgwapi/inc/class.auth_http.inc.php @@ -24,21 +24,22 @@ /* $Id$ */ - class auth - { + class auth + { + function authenticate($username, $passwd) + { + global $phpgw_info, $phpgw, $PHP_AUTH_USER; - function authenticate($username, $passwd) { - global $phpgw_info, $phpgw, $PHP_AUTH_USER; - - if (isset($PHP_AUTH_USER)) { - return True; - } else { - return False; - } - } - function change_password($old_passwd, $new_passwd) { - global $phpgw_info, $phpgw; - return False; - } - } -?> \ No newline at end of file + if (isset($PHP_AUTH_USER)) { + return True; + } else { + return False; + } + } + + function change_password($old_passwd, $new_passwd) { + global $phpgw_info, $phpgw; + return False; + } + } +?> diff --git a/phpgwapi/inc/class.auth_ldap.inc.php b/phpgwapi/inc/class.auth_ldap.inc.php index 041f0c6660..f6bc9af670 100644 --- a/phpgwapi/inc/class.auth_ldap.inc.php +++ b/phpgwapi/inc/class.auth_ldap.inc.php @@ -24,39 +24,38 @@ /* $Id$ */ - class auth - { + class auth + { + function authenticate($username, $passwd) { + global $phpgw_info, $phpgw; + // error_reporting MUST be set to zero, otherwise you'll get nasty LDAP errors with a bad login/pass... + // these are just "warnings" and can be ignored..... + error_reporting(0); - function authenticate($username, $passwd) { - global $phpgw_info, $phpgw; - // error_reporting MUST be set to zero, otherwise you'll get nasty LDAP errors with a bad login/pass... - // these are just "warnings" and can be ignored..... - error_reporting(0); - - $ldap = ldap_connect($phpgw_info['server']['ldap_host']); - - // find the dn for this uid, the uid is not always in the dn - $sri = ldap_search($ldap, $phpgw_info['server']['ldap_context'], 'uid='.$username); - $allValues = ldap_get_entries($ldap, $sri); - if($allValues['count'] > 0) - { - // we only care about the first dn - $userDN = $allValues[0]['dn']; + $ldap = ldap_connect($phpgw_info['server']['ldap_host']); - // generate a bogus password to pass if the user doesn't give us one - // this gets around systems that are anonymous search enabled - if (empty($passwd)) $passwd = crypt(microtime()); - // try to bind as the user with user suplied password - if (ldap_bind($ldap,$userDN, $passwd)) return True; - } + // find the dn for this uid, the uid is not always in the dn + $sri = ldap_search($ldap, $phpgw_info['server']['ldap_context'], 'uid='.$username); + $allValues = ldap_get_entries($ldap, $sri); + if($allValues['count'] > 0) + { + // we only care about the first dn + $userDN = $allValues[0]['dn']; - // Turn error reporting back to normal - error_reporting(7); + // generate a bogus password to pass if the user doesn't give us one + // this gets around systems that are anonymous search enabled + if (empty($passwd)) $passwd = crypt(microtime()); + // try to bind as the user with user suplied password + if (ldap_bind($ldap,$userDN, $passwd)) return True; + } + + // Turn error reporting back to normal + error_reporting(7); + + // dn not found or password wrong + return False; + } - // dn not found or password wrong - return False; - } - function change_password($old_passwd, $new_passwd, $_account_id="") { global $phpgw_info, $phpgw; @@ -65,32 +64,33 @@ { $_account_id = $phpgw_info['user']['account_id']; } - + $ds = $phpgw->common->ldapConnect(); $sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uidnumber=$_account_id"); $allValues = ldap_get_entries($ds, $sri); - + $entry['userpassword'] = $phpgw->common->encrypt_password($new_passwd); $dn = $allValues[0]["dn"]; - + if (!@ldap_modify($ds, $dn, $entry)) { return false; } - + return $encrypted_passwd; } - - function update_lastlogin($account_lid, $ip) + + function update_lastlogin($account_id, $ip) { global $phpgw; - + + $account_id = get_account_id($account_id); $now = time(); - + $phpgw->db->query("update phpgw_accounts set account_lastloginfrom='" . "$ip', account_lastlogin='" . $now - . "' where account_lid='$account_lid'",__LINE__,__FILE__); + . "' where account_id='$account_id'",__LINE__,__FILE__); } } ?> diff --git a/phpgwapi/inc/class.auth_mail.inc.php b/phpgwapi/inc/class.auth_mail.inc.php index d432a2b9da..10dc7d6c3b 100644 --- a/phpgwapi/inc/class.auth_mail.inc.php +++ b/phpgwapi/inc/class.auth_mail.inc.php @@ -23,42 +23,49 @@ /* $Id$ */ - class auth - { + class auth + { + function authenticate($username, $passwd) + { + global $phpgw_info, $phpgw; + error_reporting(error_reporting() - 2); - function authenticate($username, $passwd) { - global $phpgw_info, $phpgw; - error_reporting(error_reporting() - 2); + if ($phpgw_info['server']['mail_login_type'] == 'vmailmgr') + { + $username = $username . '@' . $phpgw_info['server']['mail_suffix']; + } + if ($phpgw_info['server']['mail_server_type']=='imap') + { + $phpgw_info['server']['mail_port'] = '143'; + } + elseif ($phpgw_info['server']['mail_server_type']=='pop3') + { + $phpgw_info['server']['mail_port'] = '110'; + } + if( $phpgw_info['server']['mail_server_type']=='pop3') + { + $mailauth = imap_open('{'.$phpgw_info['server']['mail_server'].'/pop3' + .':'.$phpgw_info['server']['mail_port'].'}INBOX', $username , $passwd); + } + else + { //assume imap + $mailauth = imap_open('{'.$phpgw_info['server']['mail_server'] + .':'.$phpgw_info['server']['mail_port'].'}INBOX', $username , $passwd); + } - if ($phpgw_info['server']['mail_login_type'] == 'vmailmgr') { - $username = $username . '@' . $phpgw_info['server']['mail_suffix']; - } - if ($phpgw_info['server']['mail_server_type']=='imap') { - $phpgw_info['server']['mail_port'] = '143'; - } elseif ($phpgw_info['server']['mail_server_type']=='pop3') { - $phpgw_info['server']['mail_port'] = '110'; - } + error_reporting(error_reporting() + 2); + if ($mailauth == False) { + return False; + } else { + imap_close($mailauth); + return True; + } + } - if( $phpgw_info['server']['mail_server_type']=='pop3') { - $mailauth = imap_open('{'.$phpgw_info['server']['mail_server'].'/pop3' - .':'.$phpgw_info['server']['mail_port'].'}INBOX', $username , $passwd); - } else { //assume imap - $mailauth = imap_open('{'.$phpgw_info['server']['mail_server'] - .':'.$phpgw_info['server']['mail_port'].'}INBOX', $username , $passwd); - } - - error_reporting(error_reporting() + 2); - if ($mailauth == False) { - return False; - } else { - imap_close($mailauth); - return True; - } - } - function change_password($old_passwd, $new_passwd) { - global $phpgw_info, $phpgw; - return False; - } - } + function change_password($old_passwd, $new_passwd) { + global $phpgw_info, $phpgw; + return False; + } + } ?> diff --git a/phpgwapi/inc/class.auth_sql.inc.php b/phpgwapi/inc/class.auth_sql.inc.php index 08bd5e6e1d..4fe7b04c0d 100644 --- a/phpgwapi/inc/class.auth_sql.inc.php +++ b/phpgwapi/inc/class.auth_sql.inc.php @@ -24,47 +24,48 @@ /* $Id$ */ - class auth - { + class auth + { + function authenticate($username, $passwd) + { + global $phpgw_info, $phpgw; + $db = $phpgw->db; - function authenticate($username, $passwd) - { - global $phpgw_info, $phpgw; - $db = $phpgw->db; - - $db->query("SELECT * FROM phpgw_accounts WHERE account_lid = '$username' AND " - . "account_pwd='" . md5($passwd) . "' AND account_status ='A'",__LINE__,__FILE__); - $db->next_record(); + $db->query("SELECT * FROM phpgw_accounts WHERE account_lid = '$username' AND " + . "account_pwd='" . md5($passwd) . "' AND account_status ='A'",__LINE__,__FILE__); + $db->next_record(); - if ($db->f('account_lid')) { - return True; - } else { - return False; - } - } + if ($db->f('account_lid')) { + return True; + } else { + return False; + } + } - function change_password($old_passwd, $new_passwd, $_accountid="") - { - global $phpgw_info, $phpgw; + function change_password($old_passwd, $new_passwd, $_accountid="") + { + global $phpgw_info, $phpgw; - $encrypted_passwd = md5($new_passwd); - $_account_id = get_account_id($_accountid); + $encrypted_passwd = md5($new_passwd); + $_account_id = get_account_id($_accountid); - $phpgw->db->query("update phpgw_accounts set account_pwd='" . md5($new_passwd) . "' " - . "where account_id='" . $_account_id . "'",__LINE__,__FILE__); - $phpgw->db->query("update phpgw_accounts set account_lastpwd_change='" . time() . "' where account_id='" - . $_account_id . "'",__LINE__,__FILE__); - - return $encrypted_passwd; - } + $phpgw->db->query("update phpgw_accounts set account_pwd='" . md5($new_passwd) . "' " + . "where account_id='" . $_account_id . "'",__LINE__,__FILE__); + $phpgw->db->query("update phpgw_accounts set account_lastpwd_change='" . time() . "' where account_id='" + . $_account_id . "'",__LINE__,__FILE__); - function update_lastlogin($account_id, $ip) - { - global $phpgw; + return $encrypted_passwd; + } - $phpgw->db->query("update phpgw_accounts set account_lastloginfrom='" - . "$ip', account_lastlogin='" . time() - . "' where account_id='$account_id'",__LINE__,__FILE__); - } - } + function update_lastlogin($account_id, $ip) + { + global $phpgw; + + $account_id = get_account_id($account_id); + + $phpgw->db->query("update phpgw_accounts set account_lastloginfrom='" + . "$ip', account_lastlogin='" . time() + . "' where account_id='$account_id'",__LINE__,__FILE__); + } + } ?>