本文整理汇总了PHP中PerchUtil::get_client_ip方法的典型用法代码示例。如果您正苦于以下问题:PHP PerchUtil::get_client_ip方法的具体用法?PHP PerchUtil::get_client_ip怎么用?PHP PerchUtil::get_client_ip使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PerchUtil
的用法示例。
在下文中一共展示了PerchUtil::get_client_ip方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticate
public function authenticate($username, $password)
{
// Passwords should never be longer than 72 characters
if (strlen($password) > 72) {
return false;
}
$username = filter_var($username, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
if ($this->activate()) {
if (PERCH_PARANOID) {
// reset any expired lockouts for this user
$sql = 'UPDATE ' . $this->table . ' SET userLastFailedLogin=NULL, userFailedLoginAttempts=0
WHERE BINARY userUsername=' . $this->db->pdb($username) . '
AND userLastFailedLogin<' . $this->db->pdb(date('Y-m-d H:i:s', strtotime('-' . PERCH_AUTH_LOCKOUT_DURATION)));
$this->db->execute($sql);
}
$sql = 'SELECT u.*, r.* FROM ' . $this->table . ' u, ' . PERCH_DB_PREFIX . 'user_roles r
WHERE u.roleID=r.roleID AND u.userEnabled=1 AND ';
if (PERCH_PARANOID) {
$sql .= 'BINARY userUsername=' . $this->db->pdb($username) . ' AND userFailedLoginAttempts<' . (int) PERCH_MAX_FAILED_LOGINS;
} else {
$sql .= 'userUsername=' . $this->db->pdb($username);
}
$sql .= ' LIMIT 1';
$result = $this->db->get_row($sql);
if (is_array($result)) {
PerchUtil::debug('User exists, checking password.');
// presume password fail.
$password_match = false;
$stored_password = $result['userPassword'];
$Hasher = PerchUtil::get_password_hasher();
// data array for user details - gets committed if passwords check out.
$data = array();
// check password type
if (substr($stored_password, 0, 3) == '$P$') {
PerchUtil::debug('Stronger password hash.');
// stronger hash, check password
if ($Hasher->CheckPassword($password, $stored_password)) {
$password_match = true;
PerchUtil::debug('Password is ok.');
} else {
PerchUtil::debug('Password failed to match.');
}
} else {
// old MD5 password
PerchUtil::debug('Old MD5 password.');
if ($stored_password == md5($password)) {
$password_match = true;
PerchUtil::debug('Password is ok. Upgrading.');
//upgrade!
$hashed_password = $Hasher->HashPassword($password);
$data['userPassword'] = $hashed_password;
} else {
PerchUtil::debug('MD5 password failed to match.');
}
}
if ($password_match) {
$this->set_details($result);
$data['userHash'] = md5(uniqid());
$data['userLastLogin'] = date('Y-m-d H:i:s');
$data['userFailedLoginAttempts'] = 0;
$data['userLastFailedLogin'] = null;
$this->update($data);
$this->result['userHash'] = $data['userHash'];
$this->set_details($result);
PerchSession::regenerate();
PerchSession::set('userID', $result['userID']);
PerchSession::set('userHash', $data['userHash']);
$this->logged_in = true;
$this->_load_privileges();
if (!$this->has_priv('perch.login')) {
PerchUtil::debug('User role does not have login privs');
$this->logout();
return false;
}
// Set cookie for front-end might-be-authed check
PerchUtil::setcookie('cmsa', 1, strtotime('+30 days'), '/');
$Perch = Perch::fetch();
$Perch->event('user.login', $this);
return true;
}
// Username checks out, but wrong password.
$data['userFailedLoginAttempts'] = (int) $result['userFailedLoginAttempts'] + 1;
$data['userLastFailedLogin'] = date('Y-m-d H:i:s');
$this->set_details($result);
$this->update($data);
if (PERCH_PARANOID && $data['userFailedLoginAttempts'] == PERCH_MAX_FAILED_LOGINS) {
$this->send_lockout_email($result['userID']);
}
}
}
PerchUtil::debug('Writing auth fail to log.');
$username = escapeshellcmd(stripslashes($username));
@syslog(LOG_INFO, 'Authentication failure for ' . $username . ' from ' . PerchUtil::get_client_ip());
return false;
}
示例2: authenticate
public function authenticate($username, $password)
{
// Passwords should never be longer than 72 characters
if (strlen($password) > 72) {
return false;
}
$username = filter_var($username, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
if ($this->activate()) {
$sql = 'SELECT u.*, r.* FROM ' . $this->table . ' u, ' . PERCH_DB_PREFIX . 'user_roles r
WHERE u.roleID=r.roleID AND u.userEnabled=1 AND userUsername=' . $this->db->pdb($username) . ' LIMIT 1';
$result = $this->db->get_row($sql);
if (is_array($result)) {
PerchUtil::debug('User exists, checking password.');
// presume password fail.
$password_match = false;
$stored_password = $result['userPassword'];
// check which type of password - default is portable
if (defined('PERCH_NONPORTABLE_HASHES') && PERCH_NONPORTABLE_HASHES) {
$portable_hashes = false;
} else {
$portable_hashes = true;
}
$Hasher = new PasswordHash(8, $portable_hashes);
// data array for user details - gets committed if passwords check out.
$data = array();
// check password type
if (substr($stored_password, 0, 3) == '$P$') {
PerchUtil::debug('Stronger password hash.');
// stronger hash, check password
if ($Hasher->CheckPassword($password, $stored_password)) {
$password_match = true;
PerchUtil::debug('Password is ok.');
} else {
PerchUtil::debug('Password failed to match.');
}
} else {
// old MD5 password
PerchUtil::debug('Old MD5 password.');
if ($stored_password == md5($password)) {
$password_match = true;
PerchUtil::debug('Password is ok. Upgrading.');
//upgrade!
$hashed_password = $Hasher->HashPassword($password);
$data['userPassword'] = $hashed_password;
} else {
PerchUtil::debug('MD5 password failed to match.');
}
}
if ($password_match) {
$this->set_details($result);
$data['userHash'] = md5(uniqid());
$data['userLastLogin'] = date('Y-m-d H:i:s');
$this->update($data);
$this->result['userHash'] = $data['userHash'];
$this->set_details($result);
PerchSession::regenerate();
PerchSession::set('userID', $result['userID']);
PerchSession::set('userHash', $data['userHash']);
$this->logged_in = true;
$this->_load_privileges();
if (!$this->has_priv('perch.login')) {
PerchUtil::debug('User role does not have login privs');
$this->logout();
return false;
}
// Set cookie for front-end might-be-authed checked
PerchUtil::setcookie('cmsa', 1, strtotime('+30 days'), '/');
$Perch = Perch::fetch();
$Perch->event('user.login', $this);
return true;
}
}
}
PerchUtil::debug('Writing auth fail to log.');
$username = escapeshellcmd(stripslashes($username));
syslog(LOG_INFO, 'Authentication failure for ' . $username . ' from ' . PerchUtil::get_client_ip());
return false;
}