Fix account_id use in update_lastlogin to use get_account_id; formatting

This commit is contained in:
Miles Lott 2001-03-26 21:36:32 +00:00
parent 5f06d2940e
commit e2afce4073
4 changed files with 134 additions and 125 deletions

View File

@ -24,21 +24,22 @@
/* $Id$ */ /* $Id$ */
class auth class auth
{ {
function authenticate($username, $passwd)
{
global $phpgw_info, $phpgw, $PHP_AUTH_USER;
function authenticate($username, $passwd) { if (isset($PHP_AUTH_USER)) {
global $phpgw_info, $phpgw, $PHP_AUTH_USER; return True;
} else {
if (isset($PHP_AUTH_USER)) { return False;
return True; }
} else { }
return False;
} function change_password($old_passwd, $new_passwd) {
} global $phpgw_info, $phpgw;
function change_password($old_passwd, $new_passwd) { return False;
global $phpgw_info, $phpgw; }
return False; }
} ?>
}
?>

View File

@ -24,39 +24,38 @@
/* $Id$ */ /* $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) { $ldap = ldap_connect($phpgw_info['server']['ldap_host']);
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'];
// generate a bogus password to pass if the user doesn't give us one // find the dn for this uid, the uid is not always in the dn
// this gets around systems that are anonymous search enabled $sri = ldap_search($ldap, $phpgw_info['server']['ldap_context'], 'uid='.$username);
if (empty($passwd)) $passwd = crypt(microtime()); $allValues = ldap_get_entries($ldap, $sri);
// try to bind as the user with user suplied password if($allValues['count'] > 0)
if (ldap_bind($ldap,$userDN, $passwd)) return True; {
} // we only care about the first dn
$userDN = $allValues[0]['dn'];
// Turn error reporting back to normal // generate a bogus password to pass if the user doesn't give us one
error_reporting(7); // 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="") function change_password($old_passwd, $new_passwd, $_account_id="")
{ {
global $phpgw_info, $phpgw; global $phpgw_info, $phpgw;
@ -65,32 +64,33 @@
{ {
$_account_id = $phpgw_info['user']['account_id']; $_account_id = $phpgw_info['user']['account_id'];
} }
$ds = $phpgw->common->ldapConnect(); $ds = $phpgw->common->ldapConnect();
$sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uidnumber=$_account_id"); $sri = ldap_search($ds, $phpgw_info["server"]["ldap_context"], "uidnumber=$_account_id");
$allValues = ldap_get_entries($ds, $sri); $allValues = ldap_get_entries($ds, $sri);
$entry['userpassword'] = $phpgw->common->encrypt_password($new_passwd); $entry['userpassword'] = $phpgw->common->encrypt_password($new_passwd);
$dn = $allValues[0]["dn"]; $dn = $allValues[0]["dn"];
if (!@ldap_modify($ds, $dn, $entry)) if (!@ldap_modify($ds, $dn, $entry))
{ {
return false; return false;
} }
return $encrypted_passwd; return $encrypted_passwd;
} }
function update_lastlogin($account_lid, $ip) function update_lastlogin($account_id, $ip)
{ {
global $phpgw; global $phpgw;
$account_id = get_account_id($account_id);
$now = time(); $now = time();
$phpgw->db->query("update phpgw_accounts set account_lastloginfrom='" $phpgw->db->query("update phpgw_accounts set account_lastloginfrom='"
. "$ip', account_lastlogin='" . $now . "$ip', account_lastlogin='" . $now
. "' where account_lid='$account_lid'",__LINE__,__FILE__); . "' where account_id='$account_id'",__LINE__,__FILE__);
} }
} }
?> ?>

View File

@ -23,42 +23,49 @@
/* $Id$ */ /* $Id$ */
class auth class auth
{ {
function authenticate($username, $passwd)
{
global $phpgw_info, $phpgw;
error_reporting(error_reporting() - 2);
function authenticate($username, $passwd) { if ($phpgw_info['server']['mail_login_type'] == 'vmailmgr')
global $phpgw_info, $phpgw; {
error_reporting(error_reporting() - 2); $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') { error_reporting(error_reporting() + 2);
$username = $username . '@' . $phpgw_info['server']['mail_suffix']; if ($mailauth == False) {
} return False;
if ($phpgw_info['server']['mail_server_type']=='imap') { } else {
$phpgw_info['server']['mail_port'] = '143'; imap_close($mailauth);
} elseif ($phpgw_info['server']['mail_server_type']=='pop3') { return True;
$phpgw_info['server']['mail_port'] = '110'; }
} }
if( $phpgw_info['server']['mail_server_type']=='pop3') { function change_password($old_passwd, $new_passwd) {
$mailauth = imap_open('{'.$phpgw_info['server']['mail_server'].'/pop3' global $phpgw_info, $phpgw;
.':'.$phpgw_info['server']['mail_port'].'}INBOX', $username , $passwd); return False;
} 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;
}
}
?> ?>

View File

@ -24,47 +24,48 @@
/* $Id$ */ /* $Id$ */
class auth class auth
{ {
function authenticate($username, $passwd)
{
global $phpgw_info, $phpgw;
$db = $phpgw->db;
function authenticate($username, $passwd) $db->query("SELECT * FROM phpgw_accounts WHERE account_lid = '$username' AND "
{ . "account_pwd='" . md5($passwd) . "' AND account_status ='A'",__LINE__,__FILE__);
global $phpgw_info, $phpgw; $db->next_record();
$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();
if ($db->f('account_lid')) { if ($db->f('account_lid')) {
return True; return True;
} else { } else {
return False; return False;
} }
} }
function change_password($old_passwd, $new_passwd, $_accountid="") function change_password($old_passwd, $new_passwd, $_accountid="")
{ {
global $phpgw_info, $phpgw; global $phpgw_info, $phpgw;
$encrypted_passwd = md5($new_passwd); $encrypted_passwd = md5($new_passwd);
$_account_id = get_account_id($_accountid); $_account_id = get_account_id($_accountid);
$phpgw->db->query("update phpgw_accounts set account_pwd='" . md5($new_passwd) . "' " $phpgw->db->query("update phpgw_accounts set account_pwd='" . md5($new_passwd) . "' "
. "where account_id='" . $_account_id . "'",__LINE__,__FILE__); . "where account_id='" . $_account_id . "'",__LINE__,__FILE__);
$phpgw->db->query("update phpgw_accounts set account_lastpwd_change='" . time() . "' where account_id='" $phpgw->db->query("update phpgw_accounts set account_lastpwd_change='" . time() . "' where account_id='"
. $_account_id . "'",__LINE__,__FILE__); . $_account_id . "'",__LINE__,__FILE__);
return $encrypted_passwd;
}
function update_lastlogin($account_id, $ip) return $encrypted_passwd;
{ }
global $phpgw;
$phpgw->db->query("update phpgw_accounts set account_lastloginfrom='" function update_lastlogin($account_id, $ip)
. "$ip', account_lastlogin='" . time() {
. "' where account_id='$account_id'",__LINE__,__FILE__); 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__);
}
}
?> ?>