Skip to content

Commit 8e80480

Browse files
committed
issue#77 Add support for remine password hashes
1 parent 8eb99e6 commit 8e80480

8 files changed

Lines changed: 123 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
### Added
99
- Support for Nextcloud 15
10-
- SHA-256, SHA-512 hash algorithm
10+
- Redmine, SHA-256, SHA-512 hash algorithms
1111
### Fixed
1212
- Loading user list when display name is null
1313
- Hide "password change form" when "Allow password change" not set
14+
### Changed
15+
- Append salt only when checked. Not by default
1416

1517
## [4.1.0] - 2018-10-28
1618
### Added

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ Name | Description | Details
7373
**Active** | Flag indicating if user can log in. | Optional.<br/>Default: true.
7474
**Provide avatar** | Flag indicating if user can change its avatar. | Optional.<br/>Default: false.
7575
**Salt** | Salt which is appended to password when checking or changing the password. | Optional.
76-
**Prepend salt** | Prepend a salt to the password instead of appending it. | Optional.<br/>Default: false.
76+
**Append salt** | Append a salt to the password. | Optional.<br/>Default: false.
77+
**Prepend salt** | Prepend a salt to the password. | Optional.<br/>Default: false.
7778

7879
#### Group table
7980

@@ -196,6 +197,7 @@ Drupal 7 | See [phpass](http://www.openwall.com/phpass/). | $S$DC7eCpJQ3SUQtW4Bp
196197
Joomla MD5 Encryption | Generates 32 chars salt. | 14d21b49b0f13e2acba962b6b0039edd:haJK0yTvBXTNMh76xwEw5RYEVpJsN8us
197198
MD5 | No salt supported. | 5f4dcc3b5aa765d61d8327deb882cf99
198199
Portable PHP password | See [phpass](http://www.openwall.com/phpass/). | $P$BxrwraqNTi4as0EI.IpiA/K.muk9ke/
200+
Redmine | Requires salt. Salt value for hash in the next column is 'salt'. | 48b75edeffd8e413341d7734f0f3391e7a5da994
199201
SHA-1 | No salt supported. | 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
200202
SHA-256 | No salt supported. | 5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8
201203
SHA-512 | No salt supported. | b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86

lib/Backend/UserBackend.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public function checkPassword(string $uid, string $password)
307307
$password = $this->addSalt($user, $password);
308308

309309
$isCorrect = $passwordAlgorithm->checkPassword(
310-
$password, $user->password
310+
$password, $user->password, $user->salt
311311
);
312312

313313
if ($user->active == false) {
@@ -366,9 +366,9 @@ private function getPasswordAlgorithm()
366366
private function addSalt(User $user, string $password): string
367367
{
368368
if ($user->salt !== null) {
369-
if (empty($this->properties[Opt::PREPEND_SALT])) {
369+
if (!empty($this->properties[Opt::APPEND_SALT])) {
370370
return $password . $user->salt;
371-
} else {
371+
} elseif (!empty($this->properties[Opt::PREPEND_SALT])) {
372372
return $user->salt . $password;
373373
}
374374
}

lib/Constant/Opt.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929
final class Opt
3030
{
31+
const APPEND_SALT = "opt.append_salt";
3132
const CASE_INSENSITIVE_USERNAME = "opt.case_insensitive_username";
3233
const CRYPTO_CLASS = "opt.crypto_class";
3334
const EMAIL_SYNC = "opt.email_sync";

lib/Crypto/Redmine.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Nextcloud - user_sql
4+
*
5+
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
6+
* @author Marcin Łojewski <dev@mlojewski.me>
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
namespace OCA\UserSQL\Crypto;
23+
24+
/**
25+
* Redmine MD5 hash implementation.
26+
*
27+
* @author Marcin Łojewski <dev@mlojewski.me>
28+
*/
29+
class Redmine extends AbstractAlgorithm
30+
{
31+
/**
32+
* @inheritdoc
33+
*/
34+
public function getPasswordHash($password, $salt = null)
35+
{
36+
if (is_null($salt)) {
37+
return false;
38+
}
39+
40+
return sha1($salt . sha1($password));
41+
}
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
protected function getAlgorithmName()
47+
{
48+
return "Redmine";
49+
}
50+
}

templates/admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ function print_select_options(
153153
print_text_input($l, "db-table-user-column-active", "Active", $_["db.table.user.column.active"]);
154154
print_text_input($l, "db-table-user-column-avatar", "Provide avatar", $_["db.table.user.column.avatar"]);
155155
print_text_input($l, "db-table-user-column-salt", "Salt", $_["db.table.user.column.salt"]);
156+
print_checkbox_input($l, "opt-append_salt", "Append salt", $_["opt.append_salt"]);
156157
print_checkbox_input($l, "opt-prepend_salt", "Prepend salt", $_["opt.prepend_salt"]); ?>
157158
</fieldset>
158159
</div>

tests/Crypto/PhpassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
use Test\TestCase;
2828

2929
/**
30-
* Unit tests for class <code>PhpassTest</code>.
30+
* Unit tests for class <code>Phpass</code>.
3131
*
3232
* @author Marcin Łojewski <dev@mlojewski.me>
3333
*/

tests/Crypto/RedmineTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* Nextcloud - user_sql
4+
*
5+
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
6+
* @author Marcin Łojewski <dev@mlojewski.me>
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
namespace Tests\UserSQL\Crypto;
23+
24+
use OCA\UserSQL\Crypto\IPasswordAlgorithm;
25+
use OCA\UserSQL\Crypto\Redmine;
26+
use OCP\IL10N;
27+
use Test\TestCase;
28+
29+
/**
30+
* Unit tests for class <code>Redmine</code>.
31+
*
32+
* @author Marcin Łojewski <dev@mlojewski.me>
33+
*/
34+
class RedmineTest extends TestCase
35+
{
36+
/**
37+
* @var IPasswordAlgorithm
38+
*/
39+
private $crypto;
40+
41+
public function testCheckPassword()
42+
{
43+
$this->assertTrue(
44+
$this->crypto->checkPassword(
45+
"password", "48b75edeffd8e413341d7734f0f3391e7a5da994", "salt"
46+
)
47+
);
48+
}
49+
50+
public function testPasswordHash()
51+
{
52+
$hash = $this->crypto->getPasswordHash("password", "salt");
53+
$this->assertTrue($this->crypto->checkPassword("password", $hash, "salt"));
54+
}
55+
56+
protected function setUp()
57+
{
58+
parent::setUp();
59+
$this->crypto = new Redmine($this->createMock(IL10N::class));
60+
}
61+
}

0 commit comments

Comments
 (0)