issue#79 Password error on sha512 with salt
Added SHA-256, SHA-512
This commit is contained in:
61
tests/Crypto/SHA256Test.php
Normal file
61
tests/Crypto/SHA256Test.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Nextcloud - user_sql
|
||||
*
|
||||
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
|
||||
* @author Marcin Łojewski <dev@mlojewski.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Tests\UserSQL\Crypto;
|
||||
|
||||
use OCA\UserSQL\Crypto\IPasswordAlgorithm;
|
||||
use OCA\UserSQL\Crypto\SHA256;
|
||||
use OCP\IL10N;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for class <code>SHA256</code>.
|
||||
*
|
||||
* @author Marcin Łojewski <dev@mlojewski.me>
|
||||
*/
|
||||
class SHA512Test extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var IPasswordAlgorithm
|
||||
*/
|
||||
private $crypto;
|
||||
|
||||
public function testCheckPassword()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->crypto->checkPassword(
|
||||
"password", "5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testPasswordHash()
|
||||
{
|
||||
$hash = $this->crypto->getPasswordHash("password");
|
||||
$this->assertTrue($this->crypto->checkPassword("password", $hash));
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->crypto = new SHA256($this->createMock(IL10N::class));
|
||||
}
|
||||
}
|
||||
62
tests/Crypto/SHA512Test.php
Normal file
62
tests/Crypto/SHA512Test.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* Nextcloud - user_sql
|
||||
*
|
||||
* @copyright 2018 Marcin Łojewski <dev@mlojewski.me>
|
||||
* @author Marcin Łojewski <dev@mlojewski.me>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Tests\UserSQL\Crypto;
|
||||
|
||||
use OCA\UserSQL\Crypto\IPasswordAlgorithm;
|
||||
use OCA\UserSQL\Crypto\SHA512;
|
||||
use OCP\IL10N;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
* Unit tests for class <code>SHA512</code>.
|
||||
*
|
||||
* @author Marcin Łojewski <dev@mlojewski.me>
|
||||
*/
|
||||
class SHA512Test extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var IPasswordAlgorithm
|
||||
*/
|
||||
private $crypto;
|
||||
|
||||
public function testCheckPassword()
|
||||
{
|
||||
$this->assertTrue(
|
||||
$this->crypto->checkPassword(
|
||||
"password",
|
||||
"b109f3bbbc244eb82441917ed06d618b9008dd09b3befd1b5e07394c706a8bb980b1d7785e5976ec049b46df5f1326af5a2ea6d103fd07c95385ffab0cacbc86"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function testPasswordHash()
|
||||
{
|
||||
$hash = $this->crypto->getPasswordHash("password");
|
||||
$this->assertTrue($this->crypto->checkPassword("password", $hash));
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->crypto = new SHA512($this->createMock(IL10N::class));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user