Thursday, August 19, 2010

Really Cool Tool!

Format my Code for Blogger : "http://formatmysourcecode.blogspot.com/"

A Random password generator

A Sample code for a Random Password Generator


package com.sreekanth.util.password;

/**
 *
 * @author sreekanth
 */

public class RandomPasswordGenerator
{
    /**
     *
     * @param n
     * @return
     */

    public static synchronized String getPassword(int n)
    {   
        char[] pwd = new char[n];
        int c  = 'A';
        int  r1 = 0;

        for (int i=0; i < n; i++)
        {
            r1 = (int)(Math.random() * 3);
       
            switch(r1)
            {
                case 0: c = '0' +  (int)(Math.random() * 10); break;
                case 1: c = 'a' +  (int)(Math.random() * 26); break;
                case 2: c = 'A' +  (int)(Math.random() * 26); break;
            }
            pwd[i] = (char)c;
        }
        return new String(pwd);
    }
   
    /**
     *
     * @return
     */
    public static synchronized String getPassword()
    {
        int length = 8; // the default password length
        return getPassword(length);
    }

    public static void main(String[] args) {}
   
}

Tuesday, August 03, 2010

Amazing Charts Tool for Java Script

I am truly impressed with the capabilities of this tool : http://www.highcharts.com/ - Excellent Support for JSON data makes it a charm to use !