openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 118f8e333de965716e653de35a1d8dcbb87e1005
parent ceb81a0f6562232b82d669d4ddb7d94a4d81b503
Author: Jan Dankert <devnull@localhost>
Date:   Fri,  1 Mar 2013 23:59:40 +0100

Für das Hashen der Kennwörter die Klasse 'Password' benutzen, damit ist Bcrypt möglich. Außerdem das Ändern des Kennwortes ermöglicht.

Diffstat:
action/LoginAction.class.php | 42++++++++++++++++++++++++++++++++++++++++++
auth/InternalAuth.class.php | 2+-
config/config-default.php | 7+++----
model/User.class.php | 30+++++++++++++-----------------
4 files changed, 59 insertions(+), 22 deletions(-)

diff --git a/action/LoginAction.class.php b/action/LoginAction.class.php @@ -822,6 +822,48 @@ class LoginAction extends Action $loginPassword = $this->getRequestVar('login_password',OR_FILTER_ALPHANUM); $newPassword1 = $this->getRequestVar('password1' ,OR_FILTER_ALPHANUM); $newPassword2 = $this->getRequestVar('password2' ,OR_FILTER_ALPHANUM); + + // Der Benutzer hat zwar ein richtiges Kennwort eingegeben, aber dieses ist abgelaufen. + // Wir versuchen hier, das neue zu setzen (sofern eingegeben). + if ( empty($newPassword1) ) + { + // Kein neues Kennwort, + // nichts zu tun... + } + else + { + $auth = new InternalAuth(); + + if ( $auth->login($loginName, $loginPassword) || $auth->mustChangePassword ) + { + if ( $newPassword1 != $newPassword2 ) + { + $this->addValidationError('password1','PASSWORDS_DO_NOT_MATCH'); + $this->addValidationError('password2',''); + return; + } + elseif ( strlen($newPassword1) < $conf['security']['password']['min_length'] ) + { + $this->addValidationError('password1','PASSWORD_MINLENGTH',array('minlength'=>$conf['security']['password']['min_length'])); + $this->addValidationError('password2',''); + return; + } + else + { + // Kennwoerter identisch und lang genug. + $user = User::loadWithName($loginName); + $user->setPassword( $newPassword1,true ); + } + } + else + { + // Anmeldung gescheitert. + $this->addNotice('user',$loginName,'LOGIN_FAILED','error',array('name'=>$loginName) ); + $this->addValidationError('login_name' ,''); + $this->addValidationError('login_password',''); + return; + } + } // Cookie setzen $cookieLifetime = 60*60*24*30*12*2; // 2 Jahre. diff --git a/auth/InternalAuth.class.php b/auth/InternalAuth.class.php @@ -40,7 +40,7 @@ SQL // Login nicht erfolgreich return false; } - elseif ( $row_user['password'] == md5( User::saltPassword($password) ) ) + elseif ( Password::check(User::pepperPassword($password),$row_user['password']) ) { // Die Kennwort-Pruefsumme stimmt mit dem aus der Datenbank �berein. // Juchuu, Login ist erfolgreich. diff --git a/config/config-default.php b/config/config-default.php @@ -740,10 +740,9 @@ $conf['security']['newuser']['autoadd'] = true; $conf['security']['newuser']['autogroups'] = ""; $conf['security']['password'] = array(); -$conf['security']['password']['random_length']='8'; -$conf['security']['password']['min_length']='6'; -$conf['security']['password']['salt']= ''; -$conf['security']['password']['salt_text']= "somerandomtext"; +$conf['security']['password']['random_length']=10; +$conf['security']['password']['min_length']=6; +$conf['security']['password']['pepper']= ''; $conf['security']['http'] = array(); $conf['security']['http']['url']= "http://example.net/restricted-area"; $conf['security']['authdb'] = array(); diff --git a/model/User.class.php b/model/User.class.php @@ -780,9 +780,12 @@ SQL 'WHERE id={userid}' ); if ( $always ) - $sql->setString('password',md5($this->saltPassword($password)) ); + // Hashsumme für Kennwort erzeugen und speichern. + // Workaround: Hashsumme auf 50 Zeichen kürzen (da die DB-Spalte nicht länger ist) + $sql->setString('password',substr(Password::hash($this->pepperPassword($password)),0,50) ); else - $sql->setString('password',$password ); + // Klartext-Kennwort, der Benutzer muss das Kennwort beim nä. Login ändern. + $sql->setString('password',$password); $sql->setInt ('userid' ,$this->userid ); @@ -1107,25 +1110,18 @@ SQL /** - * Das Kennwort "salzen". + * Das Kennwort "pfeffern". + * + * Siehe http://de.wikipedia.org/wiki/Salt_%28Kryptologie%29#Pfeffer + * für weitere Informationen. * * @param Kennwort - * @return Das gesalzene Kennwort + * @return Das gepfefferte Kennwort */ - public function saltPassword( $pass ) + public function pepperPassword( $pass ) { - switch( config('security','password','salt') ) - { - case 'userid': - return $this->userid.$pass; - case 'username': - return $this->name.$pass; - case 'custom': - return config('security','password','salt_text').$pass; - default: - return $pass; - } - + global $conf; + return $conf['security']['password']['pepper'].$pass; } }