Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stärkere Passwortverschlüsselung ; update #223
- Loading branch information
Christian Matzat
committed
Aug 8, 2013
1 parent
a09ed40
commit 0c57799
Showing
7 changed files
with
134 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/*************************************************************************** | ||
* For license information see doc/license.txt | ||
* | ||
* Cryptographic library for encryption of passwords. | ||
* | ||
* Unicode Reminder メモ | ||
***************************************************************************/ | ||
|
||
class crypt | ||
{ | ||
static function encryptPassword($password) | ||
{ | ||
// Calls the password encryption chained | ||
$pwmd5 = crypt::firstStagePasswordEncryption($password); | ||
return crypt::secondStagePasswordEncryption($pwmd5); | ||
} | ||
|
||
static function firstStagePasswordEncryption($password) | ||
{ | ||
return md5($password); | ||
} | ||
|
||
static function secondStagePasswordEncryption($password) | ||
{ | ||
global $opt; | ||
if ($opt['logic']['password_hash']) | ||
{ | ||
return hash_hmac('sha512', $password, $opt['logic']['password_salt']); | ||
} | ||
return $password; | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/*************************************************************************** | ||
* For license information see doc/license.txt | ||
* | ||
* This script converts all md5-passwords to salted hash passwords. | ||
* | ||
* Unicode Reminder メモ | ||
***************************************************************************/ | ||
|
||
global $opt; | ||
$opt['rootpath'] = '../htdocs/'; | ||
require($opt['rootpath'] . 'lib2/web.inc.php'); | ||
require($opt['rootpath'] . 'lib2/logic/crypt.class.php'); | ||
|
||
if (!isset($opt['logic']['password_salt']) || strlen($opt['logic']['password_salt']) < 32) | ||
{ | ||
echo "Warning!\nPassword Salt not set or too short!\n\n"; | ||
return; | ||
} | ||
if (!$opt['logic']['password_hash']) | ||
{ | ||
echo "Warning!\nHashed Passwords not enabled!\n\n"; | ||
return; | ||
} | ||
|
||
$rs = sql("SELECT * FROM user where password is not null"); | ||
while ($r = sql_fetch_array($rs)) | ||
{ | ||
$password = $r['password']; | ||
if (strlen($password) == 128) | ||
{ | ||
echo "Password seems to be already converted, ommit this password\n"; | ||
continue; | ||
} | ||
if (strlen($password) < 32) | ||
{ | ||
$password = crypt::firstStagePasswordEncryption($password); | ||
} | ||
$pwhash = crypt::secondStagePasswordEncryption($password); | ||
|
||
sql("UPDATE `user` SET `password`='&1' WHERE `user_id`='&2'", $pwhash, $r['user_id']); | ||
} | ||
|
||
mysql_free_result($rs); | ||
|
||
echo "Update of passwords finished.\n"; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/**************************************************************************** | ||
Unicode Reminder メモ | ||
Password Encryption Test | ||
****************************************************************************/ | ||
|
||
require '../../../../htdocs/lib2/logic/crypt.class.php'; | ||
|
||
class PasswordEncryptionTest extends PHPUnit_Framework_TestCase { | ||
|
||
function testPasswordEncryption() | ||
{ | ||
global $opt; | ||
$opt['logic']['password_hash'] = false; | ||
|
||
$plain_text = 'very important data'; | ||
|
||
$md5HashedPassword = crypt::encryptPassword($plain_text); | ||
$this->assertEquals('c75ac45eabed45d667359462b6a8e93e', $md5HashedPassword); | ||
|
||
$opt['logic']['password_hash'] = true; | ||
$opt['logic']['password_salt'] = '?S<,XyB1Y[y_Gz>b'; | ||
|
||
$encryptedPassword = crypt::encryptPassword($plain_text); | ||
$this->assertEquals('8b1d376a76e6430738d8322a6e3f4ebd5e8632f67052de7b74c8ca745bda6f11c7ea05db7de0c14bb097d3033557eb81d7fae21de988efc5353ed2f77dab504b', $encryptedPassword); | ||
} | ||
|
||
} |