[Beeframework-svn] SF.net SVN: beeframework:[268] trunk/framework/Bee/Security
Brought to you by:
b_hartmann,
m_plomer
|
From: <m_p...@us...> - 2014-10-31 07:08:33
|
Revision: 268
http://sourceforge.net/p/beeframework/code/268
Author: m_plomer
Date: 2014-10-31 07:08:22 +0000 (Fri, 31 Oct 2014)
Log Message:
-----------
- namespacing for PasswordEncoders
Modified Paths:
--------------
trunk/framework/Bee/Security/IPasswordEncoder.php
Added Paths:
-----------
trunk/framework/Bee/Security/PasswordEncoder/CryptEncoder.php
trunk/framework/Bee/Security/PasswordEncoder/MD5Encoder.php
trunk/framework/Bee/Security/PasswordEncoder/PlainTextEncoder.php
Removed Paths:
-------------
trunk/framework/Bee/Security/PasswordEncoder/Base.php
trunk/framework/Bee/Security/PasswordEncoder/Crypt.php
trunk/framework/Bee/Security/PasswordEncoder/MD5.php
trunk/framework/Bee/Security/PasswordEncoder/PlainText.php
Modified: trunk/framework/Bee/Security/IPasswordEncoder.php
===================================================================
--- trunk/framework/Bee/Security/IPasswordEncoder.php 2014-10-27 22:39:25 UTC (rev 267)
+++ trunk/framework/Bee/Security/IPasswordEncoder.php 2014-10-31 07:08:22 UTC (rev 268)
@@ -1,20 +1,20 @@
<?php
namespace Bee\Security;
-/*
- * Copyright 2008-2014 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+ /*
+ * Copyright 2008-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
/**
* <p>
@@ -23,45 +23,45 @@
*
*/
interface IPasswordEncoder {
-
+
/**
* <p>Encodes the specified raw password with an implementation specific algorithm.</p>
- * <P>This will generally be a one-way message digest such as MD5 or SHA, but may also be a plaintext
- * variant which does no encoding at all, but rather returns the same password it was fed. The latter is useful to
- * plug in when the original password must be stored as-is.</p>
- * <p>The specified salt will potentially be used by the implementation to "salt" the initial value before
- * encoding. A salt is usually a user-specific value which is added to the password before the digest is computed.
- * This means that computation of digests for common dictionary words will be different than those in the backend
- * store, because the dictionary word digests will not reflect the addition of the salt. If a per-user salt is
- * used (rather than a system-wide salt), it also means users with the same password will have different digest
- * encoded passwords in the backend store.</p>
- * <P>If a salt value is provided, the same salt value must be use when calling the {@link
- * #isPasswordValid(String, String, Object)} method. Note that a specific implementation may choose to ignore the
- * salt value (via <code>null</code>), or provide its own.</p>
+ * <P>This will generally be a one-way message digest such as MD5 or SHA, but may also be a plaintext
+ * variant which does no encoding at all, but rather returns the same password it was fed. The latter is useful to
+ * plug in when the original password must be stored as-is.</p>
+ * <p>The specified salt will potentially be used by the implementation to "salt" the initial value before
+ * encoding. A salt is usually a user-specific value which is added to the password before the digest is computed.
+ * This means that computation of digests for common dictionary words will be different than those in the backend
+ * store, because the dictionary word digests will not reflect the addition of the salt. If a per-user salt is
+ * used (rather than a system-wide salt), it also means users with the same password will have different digest
+ * encoded passwords in the backend store.</p>
+ * <P>If a salt value is provided, the same salt value must be use when calling the {@link
+ * #isPasswordValid(String, String, Object)} method. Note that a specific implementation may choose to ignore the
+ * salt value (via <code>null</code>), or provide its own.</p>
*
- * @param String $rawPass the password to encode
+ * @param string $rawPass the password to encode
* @param mixed $salt optionally used by the implementation to "salt" the raw password before encoding. A
- * <code>null</code> value is legal.
- *
- * @return String encoded password
- *
+ * <code>null</code> value is legal.
+ *
+ * @return string encoded password
+ *
*/
- function encodePassword($rawPass, $salt);
-
- /**
- * <p>Validates a specified "raw" password against an encoded password.</p>
- * <P>The encoded password should have previously been generated by {@link #encodePassword(String,
- * Object)}. This method will encode the <code>rawPass</code> (using the optional <code>salt</code>), and then
- * compared it with the presented <code>encPass</code>.</p>
- * <p>For a discussion of salts, please refer to {@link #encodePassword(String, Object)}.</p>
- *
- * @param string $encPass a pre-encoded password
- * @param string $rawPass a raw password to encode and compare against the pre-encoded password
- * @param mixed $salt optionally used by the implementation to "salt" the raw password before encoding. A
- * <code>null</code> value is legal.
- *
- * @return boolean true if the password is valid , false otherwise
- */
- function isPasswordValid($encPass, $rawPass, $salt);
-
+ function encodePassword($rawPass, $salt);
+
+ /**
+ * <p>Validates a specified "raw" password against an encoded password.</p>
+ * <P>The encoded password should have previously been generated by {@link #encodePassword(String,
+ * Object)}. This method will encode the <code>rawPass</code> (using the optional <code>salt</code>), and then
+ * compared it with the presented <code>encPass</code>.</p>
+ * <p>For a discussion of salts, please refer to {@link #encodePassword(String, Object)}.</p>
+ *
+ * @param string $encPass a pre-encoded password
+ * @param string $rawPass a raw password to encode and compare against the pre-encoded password
+ * @param mixed $salt optionally used by the implementation to "salt" the raw password before encoding. A
+ * <code>null</code> value is legal.
+ *
+ * @return boolean true if the password is valid , false otherwise
+ */
+ function isPasswordValid($encPass, $rawPass, $salt);
+
}
\ No newline at end of file
Deleted: trunk/framework/Bee/Security/PasswordEncoder/Base.php
===================================================================
--- trunk/framework/Bee/Security/PasswordEncoder/Base.php 2014-10-27 22:39:25 UTC (rev 267)
+++ trunk/framework/Bee/Security/PasswordEncoder/Base.php 2014-10-31 07:08:22 UTC (rev 268)
@@ -1,74 +0,0 @@
-<?php
-/*
- * Copyright 2008-2010 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-use Bee\Security\IPasswordEncoder;
-use Bee\Utils\Assert;
-
-abstract class Bee_Security_PasswordEncoder_Base implements IPasswordEncoder {
-
- /**
- * Enter description here...
- *
- * @param String $mergedPasswordSalt
- *
- * @return array<String>(2)
- */
- protected function demergePasswordAndSalt($mergedPasswordSalt) {
- Assert::hasText($mergedPasswordSalt, 'Cannot pass a null or empty String');
-
- $password = $mergedPasswordSalt;
- $salt = '';
-
- $saltBegins = strrpos($mergedPasswordSalt, '{');
-
- $mergedLen = strlen($mergedPasswordSalt);
- if (($saltBegins != -1) && (($saltBegins + 1) < $mergedLen)) {
- $salt = substr($mergedPasswordSalt, $saltBegins + 1, $mergedLen - 1);
- $password = substr($mergedPasswordSalt, 0, $saltBegins);
- }
-
- return array($password, $salt);
- }
-
- /**
- * Enter description here...
- *
- * @param String $password
- * @param mixed $salt
- * @param boolean $strict
- *
- * @return String
- */
- protected function mergePasswordAndSalt($password, $salt, $strict) {
- if (is_null($password)) {
- $password = "";
- }
-
- if ($strict && !is_null($salt)) {
- if (($salt.toString().lastIndexOf("{") != -1) || (salt.toString().lastIndexOf("}") != -1)) {
- throw new IllegalArgumentException("Cannot use { or } in salt.toString()");
- }
- }
-
- if ((salt == null) || "".equals(salt)) {
- return password;
- } else {
- return password + "{" + salt.toString() + "}";
- }
- }
-
-}
\ No newline at end of file
Deleted: trunk/framework/Bee/Security/PasswordEncoder/Crypt.php
===================================================================
--- trunk/framework/Bee/Security/PasswordEncoder/Crypt.php 2014-10-27 22:39:25 UTC (rev 267)
+++ trunk/framework/Bee/Security/PasswordEncoder/Crypt.php 2014-10-31 07:08:22 UTC (rev 268)
@@ -1,35 +0,0 @@
-<?php
-/*
- * Copyright 2008-2010 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-use Bee\Security\IPasswordEncoder;
-
-class Bee_Security_PasswordEncoder_Crypt implements IPasswordEncoder {
-
- public function encodePassword($rawPass, $salt) {
- return crypt($rawPass, $salt);
- }
-
- /**
- * @param string $encPass
- * @param string $rawPass
- * @param mixed $salt
- * @return bool
- */
- public function isPasswordValid($encPass, $rawPass, $salt) {
- return $encPass === $this->encodePassword($rawPass, $salt);
- }
-}
Copied: trunk/framework/Bee/Security/PasswordEncoder/CryptEncoder.php (from rev 261, trunk/framework/Bee/Security/PasswordEncoder/Crypt.php)
===================================================================
--- trunk/framework/Bee/Security/PasswordEncoder/CryptEncoder.php (rev 0)
+++ trunk/framework/Bee/Security/PasswordEncoder/CryptEncoder.php 2014-10-31 07:08:22 UTC (rev 268)
@@ -0,0 +1,46 @@
+<?php
+namespace Bee\Security\PasswordEncoder;
+
+/*
+ * Copyright 2008-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+use Bee\Security\IPasswordEncoder;
+
+class CryptEncoder implements IPasswordEncoder {
+
+ /**
+ * @param string $rawPass the password to encode
+ * @param mixed $salt optionally used by the implementation to "salt" the raw password before encoding. A
+ * <code>null</code> value is legal.
+ *
+ * @return string encoded password
+ */
+ public function encodePassword($rawPass, $salt) {
+ return crypt($rawPass, $salt);
+ }
+
+ /**
+ * @param string $encPass a pre-encoded password
+ * @param string $rawPass a raw password to encode and compare against the pre-encoded password
+ * @param mixed $salt optionally used by the implementation to "salt" the raw password before encoding. A
+ * <code>null</code> value is legal.
+ *
+ * @return boolean true if the password is valid , false otherwise
+ */
+ public function isPasswordValid($encPass, $rawPass, $salt) {
+ return $encPass === $this->encodePassword($rawPass, $salt);
+ }
+}
Deleted: trunk/framework/Bee/Security/PasswordEncoder/MD5.php
===================================================================
--- trunk/framework/Bee/Security/PasswordEncoder/MD5.php 2014-10-27 22:39:25 UTC (rev 267)
+++ trunk/framework/Bee/Security/PasswordEncoder/MD5.php 2014-10-31 07:08:22 UTC (rev 268)
@@ -1,30 +0,0 @@
-<?php
-/*
- * Copyright 2008-2010 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-use Bee\Security\IPasswordEncoder;
-
-class Bee_Security_PasswordEncoder_MD5 implements IPasswordEncoder {
-
- public function encodePassword($rawPass, $salt) {
- return md5($rawPass);
- }
-
- public function isPasswordValid($encPass, $rawPass, $salt) {
- return $encPass === md5($rawPass);
- }
-
-}
\ No newline at end of file
Copied: trunk/framework/Bee/Security/PasswordEncoder/MD5Encoder.php (from rev 261, trunk/framework/Bee/Security/PasswordEncoder/MD5.php)
===================================================================
--- trunk/framework/Bee/Security/PasswordEncoder/MD5Encoder.php (rev 0)
+++ trunk/framework/Bee/Security/PasswordEncoder/MD5Encoder.php 2014-10-31 07:08:22 UTC (rev 268)
@@ -0,0 +1,47 @@
+<?php
+namespace Bee\Security\PasswordEncoder;
+
+/*
+ * Copyright 2008-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+use Bee\Security\IPasswordEncoder;
+
+class MD5Encoder implements IPasswordEncoder {
+
+ /**
+ * todo: implement password salting
+ * @param string $rawPass the password to encode
+ * @param mixed $salt optionally used by the implementation to "salt" the raw password before encoding. A
+ * <code>null</code> value is legal.
+ *
+ * @return string encoded password
+ */
+ public function encodePassword($rawPass, $salt) {
+ return md5($rawPass);
+ }
+
+ /**
+ * @param string $encPass a pre-encoded password
+ * @param string $rawPass a raw password to encode and compare against the pre-encoded password
+ * @param mixed $salt optionally used by the implementation to "salt" the raw password before encoding. A
+ * <code>null</code> value is legal.
+ *
+ * @return boolean true if the password is valid , false otherwise
+ */
+ public function isPasswordValid($encPass, $rawPass, $salt) {
+ return $encPass === md5($rawPass);
+ }
+}
\ No newline at end of file
Deleted: trunk/framework/Bee/Security/PasswordEncoder/PlainText.php
===================================================================
--- trunk/framework/Bee/Security/PasswordEncoder/PlainText.php 2014-10-27 22:39:25 UTC (rev 267)
+++ trunk/framework/Bee/Security/PasswordEncoder/PlainText.php 2014-10-31 07:08:22 UTC (rev 268)
@@ -1,28 +0,0 @@
-<?php
-/*
- * Copyright 2008-2010 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-use Bee\Security\IPasswordEncoder;
-
-class Bee_Security_PasswordEncoder_PlainText implements IPasswordEncoder {
- public function encodePassword($rawPass, $salt) {
- return $rawPass;
- }
-
- public function isPasswordValid($encPass, $rawPass, $salt) {
- return $encPass === $rawPass;
- }
-}
\ No newline at end of file
Copied: trunk/framework/Bee/Security/PasswordEncoder/PlainTextEncoder.php (from rev 261, trunk/framework/Bee/Security/PasswordEncoder/PlainText.php)
===================================================================
--- trunk/framework/Bee/Security/PasswordEncoder/PlainTextEncoder.php (rev 0)
+++ trunk/framework/Bee/Security/PasswordEncoder/PlainTextEncoder.php 2014-10-31 07:08:22 UTC (rev 268)
@@ -0,0 +1,45 @@
+<?php
+namespace Bee\Security\PasswordEncoder;
+/*
+ * Copyright 2008-2014 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+use Bee\Security\IPasswordEncoder;
+
+class PlainTextEncoder implements IPasswordEncoder {
+
+ /**
+ * @param string $rawPass the password to encode
+ * @param mixed $salt optionally used by the implementation to "salt" the raw password before encoding. A
+ * <code>null</code> value is legal.
+ *
+ * @return string encoded password
+ */
+ public function encodePassword($rawPass, $salt) {
+ return $rawPass;
+ }
+
+ /**
+ * @param string $encPass a pre-encoded password
+ * @param string $rawPass a raw password to encode and compare against the pre-encoded password
+ * @param mixed $salt optionally used by the implementation to "salt" the raw password before encoding. A
+ * <code>null</code> value is legal.
+ *
+ * @return boolean true if the password is valid , false otherwise
+ */
+ public function isPasswordValid($encPass, $rawPass, $salt) {
+ return $encPass === $rawPass;
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|