continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r292522 - /maven/continuum/trunk/continuum-model/src/main/mdo/continuum.mdo
Date Thu, 29 Sep 2005 19:41:34 GMT
Author: evenisse
Date: Thu Sep 29 12:41:32 2005
New Revision: 292522

URL: http://svn.apache.org/viewcvs?rev=292522&view=rev
Log:
Crypt user password

Modified:
    maven/continuum/trunk/continuum-model/src/main/mdo/continuum.mdo

Modified: maven/continuum/trunk/continuum-model/src/main/mdo/continuum.mdo
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-model/src/main/mdo/continuum.mdo?rev=292522&r1=292521&r2=292522&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-model/src/main/mdo/continuum.mdo (original)
+++ maven/continuum/trunk/continuum-model/src/main/mdo/continuum.mdo Thu Sep 29 12:41:32 2005
@@ -751,6 +751,79 @@
           </association>
         </field>
       </fields>
+      <codeSegments>
+        <codeSegment>
+          <version>1.0.0+</version>
+          <code><![CDATA[
+            public void setPassword( String password )
+            {
+                setHashedPassword( crypt( password ) );
+            }
+            public boolean equalsPassword( String password )
+            {
+                if ( hashedPassword == null && password == null )
+                {
+                    return true;
+                }
+
+                if ( ( hashedPassword == null && password != null ) || ( hashedPassword
== null && password != null ) )
+                {
+                    return false;
+                }
+
+                return hashedPassword.equals( crypt( password ) );
+            }
+
+            private String crypt( String data )
+            {
+                try
+                {
+                    java.security.MessageDigest digester = java.security.MessageDigest.getInstance(
"SHA-1" );
+                    digester.reset();
+                    digester.update( data.getBytes() );
+                    return encode( digester.digest() );
+                }
+                catch( Exception e )
+                {
+                    return data;
+                }
+            }
+
+            /**
+             * Encodes a 128 bit or 160-bit byte array into a String.
+             *
+             * @param binaryData Array containing the digest
+             * @return Encoded hex string, or null if encoding failed
+             */
+            private String encode( byte[] binaryData )
+            {
+                if ( binaryData.length != 16 && binaryData.length != 20 )
+                {
+                    int bitLength = binaryData.length * 8;
+                    throw new IllegalArgumentException( "Unrecognised length for binary data:
" + bitLength + " bits" );
+                }
+
+                String retValue = "";
+
+                for ( int i = 0; i < binaryData.length; i++ )
+                {
+                    String t = Integer.toHexString( binaryData[i] & 0xff );
+        
+                    if ( t.length() == 1 )
+                    {
+                        retValue += ( "0" + t );
+                    }
+                    else
+                    {
+                        retValue += t;
+                    }
+                }
+
+                return retValue.trim();
+            }
+          ]]></code>
+        </codeSegment>
+      </codeSegments>
     </class>
 
     <class>



Mime
View raw message