package ibase.webitm.ejb.sys;
import java.text.*;
class PassWordGenerator
{
 	public String password(String userName)
 	{
 		String subStr ="",passWord ="";
 		int dateLength,timeLength,charIntVal =0,pos =0;
 		long totalLen =0;
 		StringBuffer strbuf =new StringBuffer();
		java.sql.Timestamp currDate =new java.sql.Timestamp(System.currentTimeMillis()) ;
		String leftStr="",suffixStr ="";
		int userNameLength;
		char prefixChar ='q' ,midChar ='M';
		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy HH:mm:ss");
 		System.out.println(currDate);
 		String dateStr = sdf.format(currDate);
 		sdf = new SimpleDateFormat("HH:mm:ss");
 		String timeStr = sdf.format(currDate);
 		dateLength  =dateStr.length();
 		timeLength  =timeStr.length();
 		for(int ctr =0;ctr < timeLength;ctr++)
 		{
 			char charval = dateStr.charAt(ctr) ;
 			int ascii =(int)charval;
 			strbuf.append(ascii);
 			charIntVal =0;
 			if(Character.getNumericValue(charval) != -1)
 			{
				charIntVal = Character.getNumericValue(charval);
 			}
 			totalLen = totalLen + charIntVal + timeLength;
 		
 		}
 		totalLen = Long.parseLong(strbuf.toString()) / totalLen;
 		subStr = dateStr.substring(dateStr.length()-2,dateStr.length());
		if(totalLen == 0)
		{
			passWord = strbuf.substring(strbuf.length()-10,strbuf.length());
		}
		else
		{
			
			
		  	totalLen = totalLen * Integer.parseInt(subStr);	
		  	passWord = totalLen+"";
		}
		pos = (int)((passWord.length())/2);
		//userName ="RAJENDRA";
		userName = userName.trim();
		leftStr = passWord.substring(0,pos);
		suffixStr = passWord.substring(pos);
		userNameLength =userName.length();
		for(int count = userNameLength;count >=2;count--)	
		{
			String prefixStr =userName.substring(count-2,count-1);
			prefixChar =prefixStr.charAt(0);
			if((Character.isDigit(prefixChar)) || (int)(Character.toLowerCase(prefixChar)) > 116 )continue;
			if((int)(Character.toLowerCase(prefixChar)) <= 116)
			{
				prefixChar = Character.toLowerCase(prefixChar);	
				break;
			}
			else
			{
				prefixChar = 'q';
			}	
		}
		for(int ctr =0;ctr < userName.length()-1;ctr++)
		{
			 String midStr = userName.substring(ctr,ctr+1);
			 midChar =midStr.charAt(0);
			 if(Character.isDigit(midChar)) continue;
			 if(((int)(Character.toUpperCase(midChar)) >= 65) && ((int)(Character.toUpperCase(midChar)) <= 90)	)
			 break;
			 else
			 {
			 	midChar ='M';
			 }
		}
 			passWord = prefixChar+leftStr+midChar+suffixStr;
 		return passWord;
 	}
}
