package com.infinite.focus.server.auth;

import java.util.Random;

/***
 * 
 * Create by Saboor Salaam
 * 
 */


public class KeyGenerator {
	
	
	//Generate unique product key for a new company
	public static String generateUniqueKey() {
		
		String product_key = "";
		
		
		//Generate first 4 chars
		product_key += getAlphaNumeric(4);
		
		//Generate another 3 sets of chars seperated by '-'
		for(int i = 0; i < 3;i++) {
			product_key += "-" + getAlphaNumeric(4);
		}
		
		return product_key;
	}
	
	
	//Generate unique authentication code for a new performance profile
public static String generateUniqueAuthCode() {

		//Return 3 length code
		return getAlphaNumeric(3);
}
	

//Generate random string of specified length
	public static String getAlphaNumeric(int len) {
		
	    char[] ch = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 
	        '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' };
	    
	    //create char array of specified length
	    char[] c=new char[len];
	    
	    Random random=new Random();
	    
	    //Generate N random characters 
	    for (int i = 0; i < len; i++) {
	      c[i]=ch[random.nextInt(ch.length)];
	    }
	    
	    return new String(c);
	  }

}
