Skip to content

Commit 2ef7716

Browse files
committed
'Prepend salt' toggle
1 parent f0d3d17 commit 2ef7716

5 files changed

Lines changed: 28 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
### Added
99
- Whirlpool hash algorithm
10+
- 'Prepend salt' toggle
1011
### Fixed
1112
- Error when 'Display name' not set
1213
- Encoding of iteration for 'Extended DES (Crypt)'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Name | Description | Details
4949
--- | --- | ---
5050
**Allow display name change** | With this option enabled user can change its display name. The display name change is propagated to the database. | Optional.<br/>Default: false.<br/>Requires: user *Display name* column.
5151
**Allow password change** | Can user change its password. The password change is propagated to the database. See [Hash algorithms](#hash-algorithms). | Optional.<br/>Default: false.
52+
**Prepend salt** | Prepend a salt to the password instead of appending it. See [User table](#user-table) -> **Salt**. | Optional.<br/>Default: false.
5253
**Use cache** | Use database query results cache. The cache can be cleared any time with the *Clear cache* button click. | Optional.<br/>Default: false.
5354
**Hash algorithm** | How users passwords are stored in the database. See [Hash algorithms](#hash-algorithms). | Mandatory.
5455
**Email sync** | Sync e-mail address with the Nextcloud.<br/>- *None* - Disables this feature. This is the default option.<br/>- *Synchronise only once* - Copy the e-mail address to the Nextcloud preferences if its not set.<br/>- *Nextcloud always wins* - Always copy the e-mail address to the database. This updates the user table.<br/>- *SQL always wins* - Always copy the e-mail address to the Nextcloud preferences. | Optional.<br/>Default: *None*.<br/>Requires: user *Email* column.

lib/Backend/UserBackend.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,7 @@ public function checkPassword(string $uid, string $password)
297297
return false;
298298
}
299299

300-
if ($user->salt !== null) {
301-
$password .= $user->salt;
302-
}
300+
$password = $this->addSalt($user, $password);
303301

304302
$isCorrect = $passwordAlgorithm->checkPassword(
305303
$password, $user->password
@@ -350,6 +348,27 @@ private function getPasswordAlgorithm()
350348
return $passwordAlgorithm;
351349
}
352350

351+
/**
352+
* Append or prepend salt from external column if available.
353+
*
354+
* @param User $user The user instance.
355+
* @param string $password The password.
356+
*
357+
* @return string Salted password.
358+
*/
359+
private function addSalt(User $user, string $password): string
360+
{
361+
if ($user->salt !== null) {
362+
if (empty($this->properties[Opt::PREPEND_SALT])) {
363+
return $password . $user->salt;
364+
} else {
365+
return $user->salt . $password;
366+
}
367+
}
368+
369+
return $password;
370+
}
371+
353372
/**
354373
* @inheritdoc
355374
*/
@@ -457,9 +476,7 @@ public function setPassword(string $uid, string $password): bool
457476
return false;
458477
}
459478

460-
if ($user->salt !== null) {
461-
$password .= $user->salt;
462-
}
479+
$password = $this->addSalt($user, $password);
463480

464481
$passwordHash = $passwordAlgorithm->getPasswordHash($password);
465482
if ($passwordHash === false) {

lib/Constant/Opt.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ final class Opt
3434
const HOME_MODE = "opt.home_mode";
3535
const NAME_CHANGE = "opt.name_change";
3636
const PASSWORD_CHANGE = "opt.password_change";
37+
const PREPEND_SALT = "opt.prepend_salt";
3738
const QUOTA_SYNC = "opt.quota_sync";
3839
const USE_CACHE = "opt.use_cache";
3940
}

templates/admin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ function print_select_options(
109109
<p class="settings-hint"><?php p($l->t("Here are all currently supported options.")); ?></p>
110110
<fieldset><?php
111111
print_checkbox_input($l, "opt-name_change", "Allow display name change", $_["opt.name_change"]);
112-
print_checkbox_input($l, "opt-password_change", "Allow password change", $_["opt.password_change"]); ?>
112+
print_checkbox_input($l, "opt-password_change", "Allow password change", $_["opt.password_change"]);
113+
print_checkbox_input($l, "opt-prepend_salt", "Prepend salt", $_["opt.prepend_salt"]); ?>
113114
<div class="button-right"><?php
114115
print_checkbox_input($l, "opt-use_cache", "Use cache", $_["opt.use_cache"], false); ?>
115116
<input type="submit" id="user_sql-clear_cache" value="<?php p($l->t("Clear cache")); ?>">

0 commit comments

Comments
 (0)