Skip to content

Commit fb029b8

Browse files
committed
issue#79 Password error on sha512 with salt
Added SHA-256, SHA-512
1 parent c6c3458 commit fb029b8

7 files changed

Lines changed: 247 additions & 6 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,10 @@ Drupal 7 | See [phpass](http://www.openwall.com/phpass/). | $S$DC7eCpJQ3SUQtW4Bp
195195
Joomla MD5 Encryption | Generates 32 chars salt. | 14d21b49b0f13e2acba962b6b0039edd:haJK0yTvBXTNMh76xwEw5RYEVpJsN8us
196196
MD5 | No salt supported. | 5f4dcc3b5aa765d61d8327deb882cf99
197197
Portable PHP password | See [phpass](http://www.openwall.com/phpass/). | $P$BxrwraqNTi4as0EI.IpiA/K.muk9ke/
198-
SHA1 | No salt supported. | 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
199-
SHA512 Whirlpool | No salt supported. | a96b16ebb691dbe968b0d66d0d924cff5cf5de5e0885181d00761d87f295b2bf3d3c66187c050fc01c196ff3acaa48d3561ffd170413346e934a32280d632f2e
198+
SHA-1 | No salt supported. | 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8
199+
SHA-256 | No salt supported. | 5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8
200+
SHA-512 | No salt supported. | b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86
201+
SHA-512 Whirlpool | No salt supported. | a96b16ebb691dbe968b0d66d0d924cff5cf5de5e0885181d00761d87f295b2bf3d3c66187c050fc01c196ff3acaa48d3561ffd170413346e934a32280d632f2e
200202
SSHA256 | Generates 32 chars salt. | {SSHA256}+WxTB3JxprNteeovsuSYtgI+UkVPA9lfwGoYkz3Ff7hjd1FSdmlTMkNsSExyR21KM3NvNTZ5V0p4WXJMUjFzUg==
201203
SSHA512 | Generates 32 chars salt. | {SSHA512}It+v1kAEUBbhMJYJ2swAtz+RLE6ispv/FB6G/ALhK/YWwEmrloY+0jzrWIfmu+rWUXp8u0Tg4jLXypC5oXAW00IyYnRVdEZJbE9wak96bkNRVWFCYmlJNWxrdTA0QmhL
202204
WoltLab Community Framework 2.x | Double salted bcrypt. | $2a$08$XEQDKNU/Vbootwxv5Gp7gujxFX/RUFsZLvQPYM435Dd3/p17fto02

lib/Crypto/SHA1.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use OCP\IL10N;
2525

2626
/**
27-
* SHA1 hash implementation.
27+
* SHA-1 hash implementation.
2828
*
2929
* @author Marcin Łojewski <dev@mlojewski.me>
3030
*/
@@ -53,6 +53,6 @@ public function getPasswordHash($password)
5353
*/
5454
protected function getAlgorithmName()
5555
{
56-
return "SHA1";
56+
return "SHA-1";
5757
}
5858
}

lib/Crypto/SHA256.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
use OCP\IL10N;
25+
26+
/**
27+
* SHA-256 hash implementation.
28+
*
29+
* @author Marcin Łojewski <dev@mlojewski.me>
30+
*/
31+
class SHA256 extends AbstractAlgorithm
32+
{
33+
/**
34+
* The class constructor.
35+
*
36+
* @param IL10N $localization The localization service.
37+
*/
38+
public function __construct(IL10N $localization)
39+
{
40+
parent::__construct($localization);
41+
}
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
public function getPasswordHash($password)
47+
{
48+
return hash('sha256', $password);
49+
}
50+
51+
/**
52+
* @inheritdoc
53+
*/
54+
protected function getAlgorithmName()
55+
{
56+
return "SHA-256";
57+
}
58+
}

lib/Crypto/SHA512.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
use OCP\IL10N;
25+
26+
/**
27+
* SHA-512 hash implementation.
28+
*
29+
* @author Marcin Łojewski <dev@mlojewski.me>
30+
*/
31+
class SHA512 extends AbstractAlgorithm
32+
{
33+
/**
34+
* The class constructor.
35+
*
36+
* @param IL10N $localization The localization service.
37+
*/
38+
public function __construct(IL10N $localization)
39+
{
40+
parent::__construct($localization);
41+
}
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
public function getPasswordHash($password)
47+
{
48+
return hash('sha512', $password);
49+
}
50+
51+
/**
52+
* @inheritdoc
53+
*/
54+
protected function getAlgorithmName()
55+
{
56+
return "SHA-512";
57+
}
58+
}

lib/Crypto/SHA512Whirlpool.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use OCP\IL10N;
2525

2626
/**
27-
* SHA512 Whirlpool hash implementation.
27+
* SHA-512 Whirlpool hash implementation.
2828
*
2929
* @author Marcin Łojewski <dev@mlojewski.me>
3030
*/
@@ -53,6 +53,6 @@ public function getPasswordHash($password)
5353
*/
5454
protected function getAlgorithmName()
5555
{
56-
return "SHA512 Whirlpool";
56+
return "SHA-512 Whirlpool";
5757
}
5858
}

tests/Crypto/SHA256Test.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\SHA256;
26+
use OCP\IL10N;
27+
use Test\TestCase;
28+
29+
/**
30+
* Unit tests for class <code>SHA256</code>.
31+
*
32+
* @author Marcin Łojewski <dev@mlojewski.me>
33+
*/
34+
class SHA512Test 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", "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8"
46+
)
47+
);
48+
}
49+
50+
public function testPasswordHash()
51+
{
52+
$hash = $this->crypto->getPasswordHash("password");
53+
$this->assertTrue($this->crypto->checkPassword("password", $hash));
54+
}
55+
56+
protected function setUp()
57+
{
58+
parent::setUp();
59+
$this->crypto = new SHA256($this->createMock(IL10N::class));
60+
}
61+
}

tests/Crypto/SHA512Test.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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\SHA512;
26+
use OCP\IL10N;
27+
use Test\TestCase;
28+
29+
/**
30+
* Unit tests for class <code>SHA512</code>.
31+
*
32+
* @author Marcin Łojewski <dev@mlojewski.me>
33+
*/
34+
class SHA512Test 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",
46+
"b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86"
47+
)
48+
);
49+
}
50+
51+
public function testPasswordHash()
52+
{
53+
$hash = $this->crypto->getPasswordHash("password");
54+
$this->assertTrue($this->crypto->checkPassword("password", $hash));
55+
}
56+
57+
protected function setUp()
58+
{
59+
parent::setUp();
60+
$this->crypto = new SHA512($this->createMock(IL10N::class));
61+
}
62+
}

0 commit comments

Comments
 (0)