Skip to content

Commit

Permalink
SQL Updates angepasst und die Position der Updateausführung in der in…
Browse files Browse the repository at this point in the history
…dex/admin.php nach vorn geschoben, damit sie wenigstens ausgeführt wird

PasswdCrypt Klasse mit Kommentaren versehen und noch etwas verfeinert, um Codeduplizierung zu vermeiden

Anpassung des Umgang mit alten MD5 Hashes, so dass User möglichst wenig behelligt wird
  • Loading branch information
Mairu committed Jul 3, 2012
1 parent 3e62dd8 commit 618db4f
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 141 deletions.
24 changes: 12 additions & 12 deletions admin.php
@@ -1,10 +1,11 @@
<?php
ob_start();
/**
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL)
* @copyright (C) 2000-2010 ilch.de
* @version $Id$
*/
*
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL)
* @copyright (C) 2000-2010 ilch.de
* @version $Id$
*/
define('main', true);
define('admin', true);
define('DEBUG', true);
Expand All @@ -25,29 +26,28 @@
require_once('include/includes/loader.php');
// Allgemeiner Konfig-Array
$allgAr = getAllgAr();

/* ENTWICKLUNGSVERSION SQL UPDATES */
require_once('update/update.php');
// Wartungsmodus
if ($allgAr['wartung'] == 1) {
@define('DEBUG', true);
debug ('Wartungsmodus aktiv !');
@define('DEBUG', true);
debug ('Wartungsmodus aktiv !');
}
// Menu, Nutzerverwaltung und Seitenstatistik laden
$menu = new menu();
$m = $menu->get_complete().' (Adminbereich)';
$m = $menu->get_complete() . ' (Adminbereich)';
user_identification($m);
site_statistic();
// Sprachdateien oeffnen
load_global_lang(2);
load_modul_lang(2);
// Navigation in Variable als Array speichern
$menuAr = $menu->get_menu();

/* ENTWICKLUNGSVERSION SQL UPDATES */
require_once('update/update.php');
// Modul oeffnen
if (user_has_admin_right($menu)) {
require_once('include/admin/' . $menu->get_url('admin'));
}
// Datenbank schlie�en
db_close();
debug_out();
?>
debug_out();
88 changes: 70 additions & 18 deletions include/includes/class/passwdcrypt.php
@@ -1,6 +1,19 @@
<?php
/**
* @license http://opensource.org/licenses/gpl-2.0.php The GNU General Public License (GPL)
* @copyright (C) 2000-2012 ilch.de
* @version $Id$
*/
defined('main') or die('no direct access');

/**
* PasswdCrypt
*
* @author finke <Surf-finke@gmx.de>
* @copyright Copyright (c) 2012
*/
class PasswdCrypt{
//Konstanten für den Zufalszahlen Generator
//Konstanten für den Zufallszahlen Generator
const ONLY_LETTERS = 0;
const WITH_NUMBERS = 1;
const WITH_SPECIAL_CHARACTERS = 2;
Expand All @@ -13,6 +26,9 @@ class PasswdCrypt{

private $hashAlgorithm = self::SHA256;

/**
* @param string $lvl Gibt den zu verwendenden Hashalgorithmus an (Klassenkonstante)
*/
public function __construct($lvl = ''){
mt_srand();

Expand All @@ -21,44 +37,73 @@ public function __construct($lvl = ''){
}

if(version_compare(PHP_VERSION, '5.3.0', '<')){ //Prüfen welche Hash Funktionen Verfügbar sind. Ab 5.3 werden alle Mitgeliefert
if($this->hashAlgorithm == self::SHA512 && !defined('CRYPT_SHA512')){
if($this->hashAlgorithm == self::SHA512 && !defined('CRYPT_SHA512') && CRYPT_SHA512 !== 1){
$this->hashAlgoriathm = self::SHA256; // Wenn SHA512 nicht verfügbar, versuche SHA256
}
if($this->hashAlgorithm == self::SHA256 && !defined('CRYPT_SHA256')){
if($this->hashAlgorithm == self::SHA256 && !defined('CRYPT_SHA256') && CRYPT_SHA256 !== 1){
$this->hashAlgorithm = self::BLOWFISH; // Wenn SHA256 nicht verfügbar, versuche BLOWFISH
}
if($this->hashAlgorithm == self::BLOWFISH && !defined('CRYPT_BLOWFISH')){
if($this->hashAlgorithm == self::BLOWFISH && !defined('CRYPT_BLOWFISH') && CRYPT_BLOWFISH !== 1){
$this->hashAlgorithm = self::MD5; // Wenn BLOWFISH nicht verfügbar, nutze MD5
}
}
}


public static function getRndString($size = 20, $url = self::ONLY_LETTERS){
/**
* Erstellt eine zufällige Zeichenkette
*
* @param integer $size Länge der Zeichenkette
* @param integer $chars Angabe welche Zeichen für die Zeichenkette verwendet werden
* @return string
*/
public static function getRndString($size = 20, $chars = self::ONLY_LETTERS) {
$pool = 'abcdefghijklmnopqrstuvwxyz';
$pool .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
if($url & self::WITH_NUMBERS){
if($chars & self::WITH_NUMBERS){
$pool .='0123456789';
}

if($url & self::WITH_SPECIAL_CHARACTERS){
if($chars & self::WITH_SPECIAL_CHARACTERS){
$pool .= ',.-;:_#+*~!$%&/()=?';
}

$pool = str_shuffle($pool);
$pool_size = strlen($pool);
$string ='';
for($i = 0;$i<$size; $i++){
for($i = 0; $i < $size; $i++){
$string .= $pool[mt_rand(0, $pool_size - 1)]; //!TODO Zufallszahlen aus /dev/random bzw /dev/urandom wenn verfügbar
}
return $string;
}

public function getHashAlgorithm(){
/**
* Prüft, ob der übergebene Hash, im crpyt Format ist
*
* @param mixed $hash
* @return boolean
*/
public static function isCryptHash($hash) {
return preg_match('/^\$([156]|2a)\$?/', $hash) === 1;
}

/**
* Gibt den Code der gewählten/genutzen Hashmethode zurück (Crpyt Konstante)
*
* @return string
*/
public function getHashAlgorithm() {
return $this->hashAlgorithm;
}

public function cryptPasswd($passwd, $salt = '', $rounds = 0){
/**
* Erstellt ein Hash für das übergebene Passwort
*
* @param string $passwd Klartextpasswort
* @param string $salt Salt für den Hashalgorithus
* @param integer $rounds Anzahl der Runden für den verwendeten Hashalgorithmus
* @return string Hash des Passwortes (Ausgabe von crypt())
*/
public function cryptPasswd($passwd, $salt = '', $rounds = 0) {
$salt_string = '';
switch($this->hashAlgorithm){
case self::SHA512:
Expand Down Expand Up @@ -90,21 +135,28 @@ public function cryptPasswd($passwd, $salt = '', $rounds = 0){
return $crypted_pw;
}

public function checkPasswd($passwd, $crypted_passwd){
if(empty($crypted_passwd)){
/**
* Prüft, ob das Klartextpasswort dem Hash "entspricht"
*
* @param mixed $passwd Klartextpasswort
* @param mixed $crypted_passwd Hash des Passwortes (aus der Datenbank)
* @return boolean
*/
public function checkPasswd($passwd, $crypted_passwd) {
if (empty($crypted_passwd)) {
return false;
}
if(preg_match('/^\$([156]|2a)\$?/',$crypted_passwd) === 1){
if (self::isCryptHash($crypted_passwd)) {
$new_chrypt_pw = crypt($passwd, $crypted_passwd);
if(strlen($new_chrypt_pw) < 13){
if (strlen($new_chrypt_pw) < 13) {
return false;
}
}else{
} else {
$new_chrypt_pw = md5($passwd);
}
if($new_chrypt_pw == $crypted_passwd){
if ($new_chrypt_pw == $crypted_passwd) {
return true;
}else{
} else {
return false;
}
}
Expand Down

0 comments on commit 618db4f

Please sign in to comment.