Added username length limit according to db type

MySQL: Limit 14 characters
PostgreSQL: Limit 61 characters

Limits allow for at least 1 character to be used for database usernames & passwords
This commit is contained in:
Stuart Olivera 2014-06-10 00:27:26 -04:00
commit 0b6f4b328b
2 changed files with 25 additions and 4 deletions

View file

@ -53,6 +53,20 @@ if ($_SESSION['user'] == 'admin') {
$_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg); $_SESSION['error_msg'] = __('Field "%s" can not be blank.',$error_msg);
} }
// Check username length
if (empty($_SESSION['error_msg'])) {
$username_len = strlen($_POST['v_username']);
exec (VESTA_CMD."v-list-database-types", $output, $return_var);
check_error($return_var);
if (strpos($output, "mysql") !== false)
$username_maxlen = 16 - 2;
elseif (strpos($output, "postgresql") !== false)
$username_maxlen = 63 - 2;
else
$username_maxlen = true; // Allow any length by default
if ($username_len > $username_maxlen ) $_SESSION['error_msg'] = __('Username is too long.',$error_msg);
}
// Check password length // Check password length
if (empty($_SESSION['error_msg'])) { if (empty($_SESSION['error_msg'])) {
$pw_len = strlen($_POST['v_password']); $pw_len = strlen($_POST['v_password']);

View file

@ -59,7 +59,14 @@
</tr> </tr>
<tr> <tr>
<td> <td>
<input type="text" size="20" class="vst-input" name="v_username" <?php if (!empty($v_username)) echo "value=".$v_username; ?> > <?php
exec (VESTA_CMD."v-list-database-types", $output);
if (strpos($output, "mysql") !== false)
$username_maxlength = 16 - 2;
elseif (strpos($output, "postgresql") !== false)
$username_maxlength = 63 - 2;
?>
<input type="text" size="20" class="vst-input" name="v_username" maxlength="14" <?php if (!empty($username_maxlength)) echo "value=".$username_maxlength; if (!empty($v_username)) echo "value=".$v_username; ?> >
</td> </td>
</tr> </tr>
<tr> <tr>