Source Code Cross Referenced for Password.java in  » Portal » Open-Portal » com » sun » portal » desktop » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.desktop.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved. 
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms. 
004:         */
005:
006:        package com.sun.portal.desktop.util;
007:
008:        public class Password {
009:            private static int DEFAULT_PAD_LENGTH = 15;
010:
011:            public static String encode(String plaintext) {
012:                char[] sbuf;
013:                char[] nbuf;
014:                char[] vbuf;
015:                boolean firstFound = false;
016:                int i;
017:                int j;
018:                int vj;
019:                int a;
020:                int numChars;
021:                String inter;
022:
023:                int lenn = plaintext.length();
024:                sbuf = plaintext.toCharArray();
025:                nbuf = new char[lenn];
026:                for (i = 0; i < lenn; i++) {
027:                    a = Character.getNumericValue(sbuf[i]);
028:                    if ((a >= 10) && (a <= 22)) {
029:                        nbuf[i] = (char) (sbuf[i] + 13);
030:                    } else if ((a >= 23) && (a <= 35)) {
031:                        nbuf[i] = (char) (sbuf[i] - 13);
032:                    } else {
033:                        if ((sbuf[i] >= 91 && sbuf[i] <= 96)
034:                                || (sbuf[i] >= 123 && sbuf[i] <= 127)) {
035:                            nbuf[i] = (char) (sbuf[i] - 32);
036:                        } else {
037:                            nbuf[i] = (char) (sbuf[i] - 7);
038:                        }
039:                    }
040:                }
041:
042:                //------------------------------------------------------------------
043:                // Now let's add some amount of random characters - take the first
044:                // alpha char of the string buffer and use it to determine how many
045:                // characters we'll add
046:                //------------------------------------------------------------------
047:
048:                vbuf = new char[lenn + 26];
049:                vj = 0;
050:                for (i = 0; i < lenn; i++) {
051:                    if (!firstFound) {
052:                        a = Character.getNumericValue(nbuf[i]);
053:                        if ((a >= 10) && (a <= 35)) {
054:                            vbuf[vj] = nbuf[i];
055:                            vj = vj + 1;
056:                            numChars = calcNum(nbuf[i]);
057:                            firstFound = true;
058:                            pad(vj, numChars, vbuf, firstFound);
059:                            vj += numChars;
060:
061:                        } else {
062:                            vbuf[vj] = nbuf[i];
063:                            vj = vj + 1;
064:                        }
065:                    } else {
066:                        vbuf[vj] = nbuf[i];
067:                        vj = vj + 1;
068:                    }
069:                }
070:                if (!firstFound) {
071:                    pad(vj, DEFAULT_PAD_LENGTH, vbuf, firstFound);
072:                    vj += DEFAULT_PAD_LENGTH;
073:                }
074:                return new String(vbuf, 0, vj);
075:            }
076:
077:            /** 
078:             * Decode an encoded password
079:             *
080:             * @param encodedtext The encoded password to be decoded.
081:             * @return The decoded password.
082:             **/
083:            // the following code is kept for backward compatibility reason
084:            public static String decode(String encodedtext) {
085:                char[] sbuf;
086:                char[] temp;
087:                char[] temp2;
088:                boolean found = false;
089:                int i;
090:                int a;
091:                int j;
092:                int l;
093:                int count;
094:
095:                int lenn = encodedtext.length();
096:                sbuf = encodedtext.toCharArray();
097:
098:                // get the ascii value of the 1st alpha char 
099:
100:                for (i = 0; i < lenn; i++) {
101:                    a = Character.getNumericValue(sbuf[i]);
102:                    if ((a >= 10) && (a <= 35)) {
103:                        found = true;
104:                        break;
105:                    }
106:                }
107:
108:                // check here if no alpha chars were found and exit with 
109:                // the input string
110:
111:                if (!found) {
112:                    temp2 = new char[lenn];
113:                    rot13(sbuf, temp2);
114:                    return new String(temp2, 0, lenn - DEFAULT_PAD_LENGTH);
115:                    //return encodedtext;
116:                }
117:
118:                count = sbuf[i] % 20;
119:                if (count == 0) {
120:                    count = 1;
121:                }
122:
123:                // now add the addfactor to set minmum number of chars
124:                count = count + 7;
125:
126:                // copy the non-alpha chars and the 1st alpha char
127:
128:                temp = new char[lenn];
129:                temp2 = new char[lenn];
130:                i += 1;
131:                for (l = 0; l < i; l++) {
132:                    temp[l] = sbuf[l];
133:                }
134:
135:                i += count;
136:
137:                while (i < lenn) {
138:                    temp[l++] = sbuf[i++];
139:                }
140:                rot13(temp, temp2);
141:
142:                return new String(temp2, 0, l);
143:            }
144:
145:            private static int calcNum(char c) {
146:                int x = c % 20;
147:                if (x == 0)
148:                    x++;
149:                return (x + 7);
150:            }
151:
152:            private static void rot13(char[] vbuf, char[] nbuf) {
153:                int i;
154:                int k;
155:
156:                for (i = 0; i < vbuf.length; i++) {
157:                    int a = Character.getNumericValue(vbuf[i]);
158:                    if ((a >= 10) && (a <= 22)) {
159:                        nbuf[i] = (char) (vbuf[i] + 13);
160:                    } else if ((a >= 23) && (a <= 35)) {
161:                        nbuf[i] = (char) (vbuf[i] - 13);
162:                    } else {
163:                        if ((vbuf[i] >= 59 && vbuf[i] <= 64)
164:                                || (vbuf[i] >= 91 && vbuf[i] <= 95)) {
165:                            nbuf[i] = (char) (vbuf[i] + 32);
166:                        } else {
167:                            nbuf[i] = (char) (vbuf[i] + 7);
168:                        }
169:                    }
170:                }
171:            }
172:
173:            private static void pad(int start, int numChars, char[] vbuf,
174:                    boolean found) {
175:                int ranInt;
176:                int rand;
177:                int vj = start;
178:                for (int j = 1; j <= numChars; j++) {
179:                    while (true) {
180:                        if (found) {
181:                            rand = (int) (Math.floor(Math.random() * 25) + 97);
182:                            ranInt = rand % 123;
183:                            if (ranInt < 65) {
184:                                continue;
185:                            }
186:                            if ((ranInt >= 91) && (ranInt <= 96)) {
187:                                continue;
188:                            }
189:                        } else {
190:                            rand = (int) (Math.floor(Math.random() * 25) + 33);
191:                            ranInt = rand % 127;
192:                            if (ranInt < 33) {
193:                                continue;
194:                            }
195:                            if ((ranInt >= 65) && (ranInt <= 90)) {
196:                                continue;
197:                            }
198:                            if ((ranInt >= 97) && (ranInt <= 122)) {
199:                                continue;
200:                            }
201:                        }
202:                        break;
203:                    }
204:                    vbuf[vj] = (char) ranInt;
205:                    vj = vj + 1;
206:                }
207:
208:            }
209:
210:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.