Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions lib/Horde/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Horde_Auth
* Authentication success
*/
public const REASON_SUCCESS = 0;

/**
* Authentication failure reason: Bad username and/or password
*/
Expand Down Expand Up @@ -181,9 +181,9 @@ public static function getCryptedPassword(
$j = 5;
}
$p[] = self::_toAPRMD5(
(ord($binary[$i]) << 16) |
(ord($binary[$k]) << 8) |
(ord($binary[$j])),
(ord($binary[$i]) << 16)
| (ord($binary[$k]) << 8)
| (ord($binary[$j])),
5
);
}
Expand Down Expand Up @@ -359,13 +359,13 @@ public static function genRandomPassword()
{
/* Alternate consonant and vowel random chars with two random numbers
* at the end. This should produce a fairly pronounceable password. */
return substr(self::CONSONANTS, mt_rand(0, strlen(self::CONSONANTS) - 1), 1) .
substr(self::VOWELS, mt_rand(0, strlen(self::VOWELS) - 1), 1) .
substr(self::CONSONANTS, mt_rand(0, strlen(self::CONSONANTS) - 1), 1) .
substr(self::VOWELS, mt_rand(0, strlen(self::VOWELS) - 1), 1) .
substr(self::CONSONANTS, mt_rand(0, strlen(self::CONSONANTS) - 1), 1) .
substr(self::NUMBERS, mt_rand(0, strlen(self::NUMBERS) - 1), 1) .
substr(self::NUMBERS, mt_rand(0, strlen(self::NUMBERS) - 1), 1);
return substr(self::CONSONANTS, mt_rand(0, strlen(self::CONSONANTS) - 1), 1)
. substr(self::VOWELS, mt_rand(0, strlen(self::VOWELS) - 1), 1)
. substr(self::CONSONANTS, mt_rand(0, strlen(self::CONSONANTS) - 1), 1)
. substr(self::VOWELS, mt_rand(0, strlen(self::VOWELS) - 1), 1)
. substr(self::CONSONANTS, mt_rand(0, strlen(self::CONSONANTS) - 1), 1)
. substr(self::NUMBERS, mt_rand(0, strlen(self::NUMBERS) - 1), 1)
. substr(self::NUMBERS, mt_rand(0, strlen(self::NUMBERS) - 1), 1);
}

/**
Expand Down Expand Up @@ -407,12 +407,12 @@ public static function genRandomPassword()
public static function checkPasswordPolicy($password, array $policy)
{
// Check max/min lengths if specified in the policy.
if (isset($policy['minLength']) &&
strlen($password) < $policy['minLength']) {
if (isset($policy['minLength'])
&& strlen($password) < $policy['minLength']) {
throw new Horde_Auth_Exception(sprintf(Horde_Auth_Translation::t("The password must be at least %d characters long!"), $policy['minLength']));
}
if (isset($policy['maxLength']) &&
strlen($password) > $policy['maxLength']) {
if (isset($policy['maxLength'])
&& strlen($password) > $policy['maxLength']) {
throw new Horde_Auth_Exception(sprintf(Horde_Auth_Translation::t("The password is too long; passwords may not be more than %d characters long!"), $policy['maxLength']));
}

Expand Down Expand Up @@ -496,8 +496,8 @@ public static function checkPasswordSimilarity(
) {
// Check for pass == dict, simple reverse strings, etc.
foreach ($dict as $test) {
if ((strcasecmp($password, $test) == 0) ||
(strcasecmp($password, strrev($test)) == 0)) {
if ((strcasecmp($password, $test) == 0)
|| (strcasecmp($password, strrev($test)) == 0)) {
throw new Horde_Auth_Exception(Horde_Auth_Translation::t("The password is too simple to guess."));
}
}
Expand Down
18 changes: 9 additions & 9 deletions lib/Horde/Auth/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public function authenticate($userId, $credentials, $login = true)

try {
$this->_credentials['userId'] = $userId;
if (($this->hasCapability('lock')) &&
$this->isLocked($userId)) {
if (($this->hasCapability('lock'))
&& $this->isLocked($userId)) {
$details = $this->isLocked($userId, true);
if ($details['lock_timeout'] == Horde_Lock::PERMANENT) {
$message = Horde_Auth_Translation::t("Your account has been permanently locked");
Expand All @@ -167,10 +167,10 @@ public function authenticate($userId, $credentials, $login = true)
}
return true;
} catch (Horde_Auth_Exception $e) {
if (($code = $e->getCode()) &&
$code != Horde_Auth::REASON_MESSAGE) {
if (($code == Horde_Auth::REASON_BADLOGIN) &&
$this->hasCapability('badlogincount')) {
if (($code = $e->getCode())
&& $code != Horde_Auth::REASON_MESSAGE) {
if (($code == Horde_Auth::REASON_BADLOGIN)
&& $this->hasCapability('badlogincount')) {
$this->_badLogin($userId);
}
$this->setError($code, $e->getMessage());
Expand Down Expand Up @@ -362,9 +362,9 @@ protected function _badLogin($userId)
['action' => 'login_failed', 'who' => $userId]
);
$history_log = $this->_history_api->getHistory($history_identifier);
if ($this->_params['login_block_count'] > 0 &&
$this->_params['login_block_count'] <= $history_log->count() &&
$this->hasCapability('lock')) {
if ($this->_params['login_block_count'] > 0
&& $this->_params['login_block_count'] <= $history_log->count()
&& $this->hasCapability('lock')) {
$this->lockUser($userId, $this->_params['login_block_time']);
}
} catch (Horde_History_Exception $e) {
Expand Down
48 changes: 24 additions & 24 deletions lib/Horde/Auth/Cyrsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ class Horde_Auth_Cyrsql extends Horde_Auth_Sql
*/
public function __construct(array $params = [])
{
if (!isset($params['imap']) ||
!($params['imap'] instanceof Horde_Imap_Client_Base)) {
if (!isset($params['imap'])
|| !($params['imap'] instanceof Horde_Imap_Client_Base)) {
throw new InvalidArgumentException('Missing imap parameter.');
}
$this->_imap = $params['imap'];
Expand All @@ -172,8 +172,8 @@ public function __construct(array $params = [])
*/
protected function _authenticate($userId, $credentials)
{
if (!empty($this->_params['domain_field']) &&
($this->_params['domain_field'] != 'none')) {
if (!empty($this->_params['domain_field'])
&& ($this->_params['domain_field'] != 'none')) {
/* Build the SQL query with domain. */
$query = sprintf(
'SELECT * FROM %s WHERE %s = ? AND %s = ?',
Expand All @@ -198,21 +198,21 @@ protected function _authenticate($userId, $credentials)
throw new Horde_Auth_Exception('', Horde_Auth::REASON_FAILED);
}

if (!$row ||
!$this->_comparePasswords($row[$this->_params['password_field']], $credentials['password'])) {
if (!$row
|| !$this->_comparePasswords($row[$this->_params['password_field']], $credentials['password'])) {
throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
}

$now = time();
if (!empty($this->_params['hard_expiration_field']) &&
!empty($row[$this->_params['hard_expiration_field']]) &&
($now > $row[$this->_params['hard_expiration_field']])) {
if (!empty($this->_params['hard_expiration_field'])
&& !empty($row[$this->_params['hard_expiration_field']])
&& ($now > $row[$this->_params['hard_expiration_field']])) {
throw new Horde_Auth_Exception('', Horde_Auth::REASON_EXPIRED);
}

if (!empty($this->_params['soft_expiration_field']) &&
!empty($row[$this->_params['soft_expiration_field']]) &&
($now > $row[$this->_params['soft_expiration_field']])) {
if (!empty($this->_params['soft_expiration_field'])
&& !empty($row[$this->_params['soft_expiration_field']])
&& ($now > $row[$this->_params['soft_expiration_field']])) {
$this->setCredential('change', true);
}
}
Expand All @@ -227,8 +227,8 @@ protected function _authenticate($userId, $credentials)
*/
public function addUser($userId, $credentials)
{
if (!empty($this->_params['domain_field']) &&
($this->_params['domain_field'] != 'none')) {
if (!empty($this->_params['domain_field'])
&& ($this->_params['domain_field'] != 'none')) {
[$name, $domain] = explode('@', $userId);

$query = sprintf(
Expand Down Expand Up @@ -267,8 +267,8 @@ public function addUser($userId, $credentials)
try {
$this->_imap->createMailbox($mailbox);
$this->_imap->setACL($mailbox, $this->_params['cyradmin'], ['rights' => 'lrswipcda']);
if (isset($this->_params['quota']) &&
($this->_params['quota'] >= 0)) {
if (isset($this->_params['quota'])
&& ($this->_params['quota'] >= 0)) {
$this->_imap->setQuota($mailbox, ['storage' => $this->_params['quota']]);
}
} catch (Horde_Imap_Client_Exception $e) {
Expand All @@ -293,8 +293,8 @@ public function addUser($userId, $credentials)
*/
public function removeUser($userId)
{
if (!empty($this->_params['domain_field']) &&
($this->_params['domain_field'] != 'none')) {
if (!empty($this->_params['domain_field'])
&& ($this->_params['domain_field'] != 'none')) {
[$name, $domain] = explode('@', $userId);

/* Build the SQL query. */
Expand Down Expand Up @@ -342,8 +342,8 @@ public function removeUser($userId)
*/
public function listUsers($sort = false)
{
if (!empty($this->_params['domain_field']) &&
($this->_params['domain_field'] != 'none')) {
if (!empty($this->_params['domain_field'])
&& ($this->_params['domain_field'] != 'none')) {
/* Build the SQL query with domain. */
$query = sprintf(
'SELECT %s, %s FROM %s',
Expand Down Expand Up @@ -371,8 +371,8 @@ public function listUsers($sort = false)

/* Loop through and build return array. */
$users = [];
if (!empty($this->_params['domain_field']) &&
($this->_params['domain_field'] != 'none')) {
if (!empty($this->_params['domain_field'])
&& ($this->_params['domain_field'] != 'none')) {
foreach ($result as $ar) {
if (!in_array($ar[$this->_params['username_field']], $this->_params['hidden_accounts'])) {
$users[] = $ar[$this->_params['username_field']] . '@' . $ar[$this->_params['domain_field']];
Expand All @@ -399,8 +399,8 @@ public function listUsers($sort = false)
*/
public function updateUser($oldID, $newID, $credentials)
{
if (!empty($this->_params['domain_field']) &&
($this->_params['domain_field'] != 'none')) {
if (!empty($this->_params['domain_field'])
&& ($this->_params['domain_field'] != 'none')) {
[$name, $domain] = explode('@', $oldID);
/* Build the SQL query with domain. */
$query = sprintf(
Expand Down
8 changes: 4 additions & 4 deletions lib/Horde/Auth/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public function __construct(array $params = [])
*/
protected function _authenticate($userId, $credentials)
{
if (empty($credentials['password']) ||
empty($this->_users[$userId])) {
if (empty($credentials['password'])
|| empty($this->_users[$userId])) {
throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
}

Expand Down Expand Up @@ -122,8 +122,8 @@ public function listUsers($sort = false)
*/
public function transparent()
{
if (empty($_SERVER['PHP_AUTH_USER']) ||
empty($_SERVER['PHP_AUTH_PW'])) {
if (empty($_SERVER['PHP_AUTH_USER'])
|| empty($_SERVER['PHP_AUTH_PW'])) {
return false;
}

Expand Down
14 changes: 7 additions & 7 deletions lib/Horde/Auth/Ldap.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ protected function _authenticate($userId, $credentials)

if ($this->_params['password_expiration'] == 'yes') {
$shadow = $this->_lookupShadow($dn);
if ($shadow['shadowmax'] && $shadow['shadowlastchange'] &&
$shadow['shadowwarning']) {
if ($shadow['shadowmax'] && $shadow['shadowlastchange']
&& $shadow['shadowwarning']) {
$today = floor(time() / 86400);
$toexpire = $shadow['shadowlastchange'] +
$shadow['shadowmax'] - $today;
$toexpire = $shadow['shadowlastchange']
+ $shadow['shadowmax'] - $today;

$warnday = $shadow['shadowlastchange'] + $shadow['shadowmax'] - $shadow['shadowwarning'];
if ($today >= $warnday) {
Expand Down Expand Up @@ -368,9 +368,9 @@ public function updateUser(

/* If shadowmin hasn't yet expired only change when we are
administrator */
if ($shadow['shadowlastchange'] &&
$shadow['shadowmin'] &&
($shadow['shadowlastchange'] + $shadow['shadowmin'] > (time() / 86400))) {
if ($shadow['shadowlastchange']
&& $shadow['shadowmin']
&& ($shadow['shadowlastchange'] + $shadow['shadowmin'] > (time() / 86400))) {
throw new Horde_Auth_Exception('Minimum password age has not yet expired');
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Horde/Auth/Msad.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public function addUser($accountName, $credentials)
$entry['objectclass'][2] = "organizationalPerson";
$entry['objectclass'][3] = "user";

$entry['description'] = (isset($credentials['description'])) ?
$credentials['description'] : 'New horde user';
$entry['description'] = (isset($credentials['description']))
? $credentials['description'] : 'New horde user';

if ($this->_params['ssl']) {
$entry["AccountDisabled"] = false;
Expand Down
4 changes: 2 additions & 2 deletions lib/Horde/Auth/Passwd.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ protected function _authenticate($userId, $credentials)
throw new Horde_Auth_Exception('', Horde_Auth::REASON_FAILED);
}

if (!isset($this->_users[$userId]) ||
!$this->_comparePasswords($this->_users[$userId]['password'], $credentials['password'])) {
if (!isset($this->_users[$userId])
|| !$this->_comparePasswords($this->_users[$userId]['password'], $credentials['password'])) {
throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
}

Expand Down
24 changes: 12 additions & 12 deletions lib/Horde/Auth/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ public function __construct(array $params = [])
parent::__construct($params);

/* Only allow limits when there is a storage configured */
if ((empty($params['soft_expiration_field'])) &&
($params['soft_expiration_window'] > 0)) {
if ((empty($params['soft_expiration_field']))
&& ($params['soft_expiration_window'] > 0)) {
throw new InvalidArgumentException('You cannot set [soft_expiration_window] without [soft_expiration_field].');
}

if (($params['hard_expiration_field'] == '') &&
($params['hard_expiration_window'] > 0)) {
if (($params['hard_expiration_field'] == '')
&& ($params['hard_expiration_window'] > 0)) {
throw new InvalidArgumentException('You cannot set [hard_expiration_window] without [hard_expiration_field].');
}

Expand Down Expand Up @@ -142,21 +142,21 @@ protected function _authenticate($userId, $credentials)
throw new Horde_Auth_Exception('', Horde_Auth::REASON_FAILED);
}

if (!$row ||
!$this->_comparePasswords($row[$this->_params['password_field']], $credentials['password'])) {
if (!$row
|| !$this->_comparePasswords($row[$this->_params['password_field']], $credentials['password'])) {
throw new Horde_Auth_Exception('', Horde_Auth::REASON_BADLOGIN);
}

$now = time();
if (!empty($this->_params['hard_expiration_field']) &&
!empty($row[$this->_params['hard_expiration_field']]) &&
($now > $row[$this->_params['hard_expiration_field']])) {
if (!empty($this->_params['hard_expiration_field'])
&& !empty($row[$this->_params['hard_expiration_field']])
&& ($now > $row[$this->_params['hard_expiration_field']])) {
throw new Horde_Auth_Exception('', Horde_Auth::REASON_EXPIRED);
}

if (!empty($this->_params['soft_expiration_field']) &&
!empty($row[$this->_params['soft_expiration_field']]) &&
($now > $row[$this->_params['soft_expiration_field']])) {
if (!empty($this->_params['soft_expiration_field'])
&& !empty($row[$this->_params['soft_expiration_field']])
&& ($now > $row[$this->_params['soft_expiration_field']])) {
$this->setCredential('change', true);
$this->setCredential('expire', $now);
}
Expand Down
10 changes: 5 additions & 5 deletions lib/Horde/Auth/X509.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,16 @@ public function transparent()
throw new Horde_Auth_Exception('SSL not enabled on server.');
}

if (empty($_SERVER[$this->_params['username_field']]) ||
empty($_SERVER[$this->_params['certificate_field']])) {
if (empty($_SERVER[$this->_params['username_field']])
|| empty($_SERVER[$this->_params['certificate_field']])) {
return false;
}

// Valid for client auth?
$cert = openssl_x509_read($_SERVER[$this->_params['certificate_field']]);
if (!$this->_params['ignore_purpose'] &&
!openssl_x509_checkpurpose($cert, X509_PURPOSE_SSL_CLIENT) &&
!openssl_x509_checkpurpose($cert, X509_PURPOSE_ANY)) {
if (!$this->_params['ignore_purpose']
&& !openssl_x509_checkpurpose($cert, X509_PURPOSE_SSL_CLIENT)
&& !openssl_x509_checkpurpose($cert, X509_PURPOSE_ANY)) {
return false;
}

Expand Down
7 changes: 4 additions & 3 deletions migration/Horde/Auth/1_horde_auth_base_tables.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
*/
class HordeAuthBaseTables extends Horde_Db_Migration_Base
Expand All @@ -8,9 +9,9 @@ class HordeAuthBaseTables extends Horde_Db_Migration_Base
public function up()
{
if (!in_array('horde_users', $this->tables())) {
$t = $this->createTable('horde_users', array('autoincrementKey' => array('user_uid')));
$t->column('user_uid', 'string', array('limit' => 255, 'null' => false));
$t->column('user_pass', 'string', array('limit' => 255, 'null' => false));
$t = $this->createTable('horde_users', ['autoincrementKey' => ['user_uid']]);
$t->column('user_uid', 'string', ['limit' => 255, 'null' => false]);
$t->column('user_pass', 'string', ['limit' => 255, 'null' => false]);
$t->column('user_soft_expiration_date', 'integer');
$t->column('user_hard_expiration_date', 'integer');
$t->end();
Expand Down
Loading
Loading