Skip to content

Commit

Permalink
Fix #13163: Remove limitation on password length with MD5 authentication
Browse files Browse the repository at this point in the history
A new function auth_get_password_max_size was added in authentication_api.php,
to return the maximum length of the password, taking the login method into
consideration: limited to the database field size (PASSLEN) for PLAIN and
BASIC_AUTH, or to new constant MAX_PASSWORD_SIZE for other, hash-based methods.

The return value is used to define the maxlength attribute of all the password
fields.
  • Loading branch information
dregad committed Jul 21, 2011
1 parent 9fae933 commit 4664aeb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
4 changes: 2 additions & 2 deletions account_page.php
Expand Up @@ -154,7 +154,7 @@
<?php } ?>
</td>
<td>
<input type="password" size="32" maxlength="<?php echo PASSLEN;?>" name="password" />
<input type="password" size="32" maxlength="<?php echo auth_get_password_max_size(); ?>" name="password" />
</td>
</tr>

Expand All @@ -169,7 +169,7 @@
<?php } ?>
</td>
<td>
<input type="password" size="32" maxlength="<?php echo PASSLEN;?>" name="password_confirm" />
<input type="password" size="32" maxlength="<?php echo auth_get_password_max_size(); ?>" name="password_confirm" />
</td>
</tr>

Expand Down
27 changes: 25 additions & 2 deletions core/authentication_api.php
Expand Up @@ -328,6 +328,29 @@ function auth_automatic_logon_bypass_form() {
return false;
}

/**
* Return the user's password maximum length
*
* @return int
* @param int $p_field_size size of the field, defaults to 32
* @access public
*/
function auth_get_password_max_size() {

switch( config_get( 'login_method' ) ) {

# Max password size cannot be bigger than the database field
case PLAIN:
case BASIC_AUTH:
return PASSLEN;

# Not sure how to handle HTTP_AUTH
# All other cases, i.e. password is stored as a hash
default:
return PASSWORD_MAX_SIZE;
}
}

/**
* Return true if the password for the user id given matches the given
* password (taking into account the global login method)
Expand Down Expand Up @@ -412,7 +435,7 @@ function auth_process_plain_password( $p_password, $p_salt = null, $p_method = n
break;
}

# cut this off to PASSLEN cahracters which the largest possible string in the database
# cut this off to PASSLEN characters which the largest possible string in the database
return utf8_substr( $t_processed_password, 0, PASSLEN );
}

Expand Down Expand Up @@ -696,7 +719,7 @@ function auth_reauthenticate_page( $p_user_id, $p_username ) {

<tr class="row-2">
<td class="category"><?php echo lang_get( 'password' );?></td>
<td><input type="password" name="password" size="16" maxlength="<?php echo PASSLEN;?>" /></td>
<td><input type="password" name="password" size="32" maxlength="<?php echo auth_get_password_max_size(); ?>" /></td>
</tr>

<tr>
Expand Down
3 changes: 3 additions & 0 deletions core/constant_inc.php
Expand Up @@ -525,4 +525,7 @@
define( 'REALLEN', 64);
define( 'PASSLEN', 32);

# Maximum size for the user's password when storing it as a hash
define( 'PASSWORD_MAX_SIZE', 1024 );

define( 'SECONDS_PER_DAY', 86400 );
2 changes: 1 addition & 1 deletion login_page.php
Expand Up @@ -129,7 +129,7 @@
<?php echo lang_get( 'password' ) ?>
</td>
<td>
<input type="password" name="password" size="16" maxlength="<?php echo PASSLEN;?>" />
<input type="password" name="password" size="28" maxlength="<?php echo auth_get_password_max_size(); ?>" />
</td>
</tr>
<tr class="row-1">
Expand Down
4 changes: 2 additions & 2 deletions manage_user_create_page.php
Expand Up @@ -87,15 +87,15 @@
<?php echo lang_get( 'password' ) ?>
</td>
<td>
<input type="password" name="password" size="32" maxlength="<?php echo PASSLEN;?>" />
<input type="password" name="password" size="32" maxlength="<?php echo auth_get_password_max_size(); ?>" />
</td>
</tr>
<tr <?php echo helper_alternate_class() ?>>
<td class="category">
<?php echo lang_get( 'verify_password' ) ?>
</td>
<td>
<input type="password" name="password_verify" size="32" maxlength="<?php echo PASSLEN;?>" />
<input type="password" name="password_verify" size="32" maxlength="<?php echo auth_get_password_max_size(); ?>" />
</td>
</tr>
<?php
Expand Down

0 comments on commit 4664aeb

Please sign in to comment.