You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2003/02/12 05:18:33 UTC

cvs commit: jakarta-jetspeed/src/java/org/apache/jetspeed/services JetspeedSecurity.java

taylor      2003/02/11 20:18:33

  Modified:    src/java/org/apache/jetspeed/services JetspeedSecurity.java
  Log:
  Added 3 methods to Security Service to generate passwords
  - generateMixedCasePassword
  - generateLowerCasePassword
  - generateUpperCasePassword
  
  Revision  Changes    Path
  1.14      +91 -1     jakarta-jetspeed/src/java/org/apache/jetspeed/services/JetspeedSecurity.java
  
  Index: JetspeedSecurity.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/JetspeedSecurity.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- JetspeedSecurity.java	10 Sep 2002 15:17:29 -0000	1.13
  +++ JetspeedSecurity.java	12 Feb 2003 04:18:33 -0000	1.14
  @@ -125,6 +125,33 @@
   
       public static final String JETSPEED_ROLE_USER = "user";
       public static final String JETSPEED_ROLE_ADMIN = "admin";
  +   
  +    /**
  +     * Alphabet consisting of upper and lowercase letters A-Z and
  +     * the digits 0-9 Used to make a random password.
  +     */
  +    public static final char[] NUMBERS_AND_LETTERS_ALPHABET = {
  +        'A','B','C','D','E','F','G','H',
  +        'I','J','K','L','M','N','O','P',
  +        'Q','R','S','T','U','V','W','X',
  +        'Y','Z','a','b','c','d','e','f',
  +        'g','h','i','j','k','l','m','n',
  +        'o','p','q','r','s','t','u','v',
  +        'w','x','y','z','0','1','2','3',
  +        '4','5','6','7','8','9',
  +    };
  +    
  +    /**
  +     * Alphabet consisting of lowercase letters a-z and
  +     * the digits 0-9 Used to make a random password.
  +     */
  +    public static final char[] LC_NUMBERS_AND_LETTERS_ALPHABET = {
  +        'a','b','c','d','e','f',
  +        'g','h','i','j','k','l','m','n',
  +        'o','p','q','r','s','t','u','v',
  +        'w','x','y','z','0','1','2','3',
  +        '4','5','6','7','8','9',
  +    };
   
       /** 
        * Commodity method for getting a reference to the service
  @@ -682,5 +709,68 @@
           return JetspeedPermissionManagement.getPermission(permissionName);
       }
   
  +   /**
  +     * A utility method that will generate a password consisting of random numbers and letters of length N from a specified character array
  +     * 
  +     * @param length
  +     * @param characters
  +     * @return String
  +     * @throws JetspeedSecurityException
  +     * @author <a href="mailto:ben.woodward@bbc.co.uk">Ben Woodward</a>
  +     */
  +    private static String generatePassword(int length, char[] characters)
  +    throws JetspeedSecurityException
  +    {
  +        String password = "";
  +        int randomNumber = 0;
  +        for (int ia = 0; ia < length; ia++)
  +        {            
  +            randomNumber=(int)(Math.random()*NUMBERS_AND_LETTERS_ALPHABET.length);
  +            password += characters[randomNumber];
  +        }
  +        return password;
  +    }
  +
  +    
  +    /**
  +     * A utility method that will generate a password consisting of random numbers and letters of length N
  +     * 
  +     * @param length
  +     * @return String
  +     * @throws JetspeedSecurityException
  +     * @author <a href="mailto:ben.woodward@bbc.co.uk">Ben Woodward</a>
  +     */
  +    public static String generateMixedCasePassword(int length)
  +    throws JetspeedSecurityException
  +    {
  +        return generatePassword(length, NUMBERS_AND_LETTERS_ALPHABET);
  +    }
  +    
  +    /**
  +     * A utility method that will generate a lowercase password consisting of random numbers and letters of length N
  +     * 
  +     * @param length
  +     * @return String
  +     * @throws JetspeedSecurityException
  +     * @author <a href="mailto:ben.woodward@bbc.co.uk">Ben Woodward</a>
  +     */
  +    public static String generateLowerCasePassword(int length)
  +    throws JetspeedSecurityException
  +    {
  +        return generatePassword(length, LC_NUMBERS_AND_LETTERS_ALPHABET).toLowerCase();
  +    }
  +    
  +    /**
  +     * A utility method that will generate an uppercase password consisting of random numbers and letters of length N
  +     * 
  +     * @param length
  +     * @return String
  +     * @throws JetspeedSecurityException
  +     */
  +    public static String generateUpperCasePassword(int length)
  +    throws JetspeedSecurityException
  +    {
  +        return generatePassword(length, LC_NUMBERS_AND_LETTERS_ALPHABET).toUpperCase();
  +    }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org