01: /**********************************************************************************
02: * $URL:https://source.sakaiproject.org/svn/osp/trunk/common/api-impl/src/java/org/theospi/portfolio/security/impl/PasswordGeneratorImpl.java $
03: * $Id:PasswordGeneratorImpl.java 9134 2006-05-08 20:28:42Z chmaurer@iupui.edu $
04: ***********************************************************************************
05: *
06: * Copyright (c) 2005, 2006 The Sakai Foundation.
07: *
08: * Licensed under the Educational Community License, Version 1.0 (the "License");
09: * you may not use this file except in compliance with the License.
10: * You may obtain a copy of the License at
11: *
12: * http://www.opensource.org/licenses/ecl1.php
13: *
14: * Unless required by applicable law or agreed to in writing, software
15: * distributed under the License is distributed on an "AS IS" BASIS,
16: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: * See the License for the specific language governing permissions and
18: * limitations under the License.
19: *
20: **********************************************************************************/package org.theospi.portfolio.security.impl;
21:
22: import java.util.Random;
23:
24: import org.sakaiproject.metaobj.security.PasswordGenerator;
25:
26: public class PasswordGeneratorImpl implements PasswordGenerator {
27: private int length;
28:
29: public String generate() {
30: return generate(getLength());
31: }
32:
33: public String generate(int length) {
34: Random rand = new Random();
35: char[] pass = new char[length];
36: for (int i = 0; i < length; i++) {
37: int val = rand.nextInt(52);
38: // need to add appropriate values to get to the ascii values
39: if (val < 26)
40: val += 65;
41: else
42: val += 71;
43: pass[i] = (char) val;
44: }
45: return new String(pass);
46: }
47:
48: public int getLength() {
49: return length;
50: }
51:
52: public void setLength(int length) {
53: this.length = length;
54: }
55: }
|