User login (non-guest) basicly finished, news stubs added, registration and final...
[shipsimu.git] / application / ship-simu / main / login / class_ShipSimuUserLogin.php
index 75bc8fa1384b8b8dc2edbd9c9860b362cc28b858..1f62ded44872b635a679bc03b8acde9156a65ce2 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 class ShipSimuUserLogin extends BaseFrameworkSystem implements LoginableUser {
+       /**
+        * The hashed password
+        */
+       private $hashedPassword = "";
+
        /**
         * Protected constructor
         *
@@ -134,6 +139,33 @@ class ShipSimuUserLogin extends BaseFrameworkSystem implements LoginableUser {
                // Return the result
                return $loginDone;
        }
+
+       /**
+        * Encrypt the given request key or throw an exception if the key was not
+        * found in the request
+        *
+        * @param       $requestKey             Key in request class
+        * @return      void
+        */
+       public function encryptPassword ($requestKey) {
+               // Check if the password is found in the request
+               if ($this->getRequestInstance()->isRequestElementSet($requestKey)) {
+                       // So encrypt the password and store it for later usage in
+                       // the request:
+
+                       // Get the plain password
+                       $plainPassword = $this->getRequestInstance()->getRequestElement($requestKey);
+
+                       // Get user instance
+                       $userInstance = Registry::getRegistry()->getInstance('user');
+
+                       // Get a crypto helper and hash the password
+                       $this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashPassword($plainPassword, $userInstance->getPasswordHash());
+
+                       // Store the hash back in the request
+                       $this->getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword);
+               } // END - if
+       }
 }
 
 // [EOF]