Commit 114fa217 authored by gahmad's avatar gahmad

Changes made in component to encrypt the password . Request id : SY2ASUN004


git-svn-id: http://15.206.35.175/svn/proteus/business-java/trunk@91700 ce508802-f39f-4f6c-b175-0d175dae99d5
parent 8b9de872
......@@ -4,16 +4,15 @@ import ibase.system.config.ConnDriver;
import ibase.webitm.ejb.ValidatorEJB;
import ibase.webitm.utility.ITMException;
import ibase.utility.*;
import java.rmi.RemoteException;
import java.security.MessageDigest;
import java.util.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import org.w3c.dom.*;
import ibase.webitm.ejb.*;
import ibase.webitm.utility.ITMException;
......@@ -98,6 +97,8 @@ public class SysGenPassword extends ValidatorEJB implements SysGenPasswordLocal
String userId="", errCode = "",resultString = "";
PreparedStatement pstmt = null;
ResultSet rs = null;
String encryptPwd="";//Gulzar on 4/16/2012
String encryptPwdSha="";//Gulzar on 4/16/2012
String sql ="",formatCode ="",refSer ="",tranIdCol ="",eventContext ="";
String refId ="",objName ="",genPassWord ="",winName ="";
int lineNo =0, k=0;
......@@ -112,7 +113,6 @@ public class SysGenPassword extends ValidatorEJB implements SysGenPasswordLocal
dom = parseString(xmlString1);
objName = "user";
winName = "w_user";
NodeList parentNodeList = null;
NodeList childNodeList = null;
Node parentNode = null;
......@@ -238,35 +238,114 @@ public class SysGenPassword extends ValidatorEJB implements SysGenPasswordLocal
commInfo.append("</MAIL><XML_DATA>"+xmlStringComp+"</XML_DATA>");
commInfo.append("</ROOT>");
//System.out.println("[SysGenPasswordEJB] commInfo..................."+commInfo);
EMail email = new EMail();
email.sendMail(commInfo.toString(), "ITM");
email = null;
/**********Modified by Rakesh kumar on 13/04/12 ***********/
//convertIntoSHA256(genPassWord) used to convert Encrypted password
encryptPwd = encryptPassword(genPassWord);
System.out.println("encryptPwd =["+encryptPwd+"]");
//encryptPwdSha = convertIntoSHA256(genPassWord);
//System.out.println("encryptPwdSha =["+encryptPwdSha+"]");
if(errCode.trim().length() == 0 || errCode == null )
{
errCode = "<Root><Message>Success</Message></Root>";
sql= "update users set pass_wd ='"+genPassWord+"' where code = '"+code+"' " ;
//Commented and changes by Rakesh
//sql= "update users set pass_wd ='"+genPassWord+"' where code = '"+code+"' " ;
/**********Changed by Rakesh kumar on 13/04/12 ***********/
//Sql Query for Encrypted passward
sql= "update users set pass_wd = ? where code = ? " ;
//System.out.println("[SysGenPasswordEJB] SQL..................."+sql);
pstmt = conn.prepareStatement(sql);
pstmt.setString( 1, encryptPwd );
pstmt.setString( 2, code );
int upd = pstmt.executeUpdate();
if(upd > 0)
{
System.out.println("pass word updated...................");
System.out.println("password updated...................");
}
pstmt.close();
pstmt = null;
//End changes by Rakesh
}
}
}
catch (RemoteException e1) {
e1.printStackTrace();
throw new ITMException(e1);
}
catch (ITMException e1) {
e1.printStackTrace();
throw new ITMException(e1);
}
catch(Exception e)
{
e.printStackTrace();
throw new ITMException(e);
}
return errCode;
}
/*** written by Rakesh Kumar on 13/04/12 ***
*** convertIntoSHA256(String dpwd) method for converted into Encrypted password format ****/
private String convertIntoSHA256(String dpwd) throws Exception
{
System.out.println("dpwd =["+dpwd+"]");
StringBuffer hexString = new StringBuffer();
try
{
MessageDigest md = MessageDigest.getInstance("SHA-256"); //$NON-NLS-1$
md.update(dpwd.getBytes(CommonConstants.ENCODING)); //$NON-NLS-1$
byte byteData[] = md.digest();
//convert the byte to hex format method 1
for (int i=0;i<byteData.length;i++)
{
String hex=Integer.toHexString(0xff & byteData[i]);
if(hex.length()==1) hexString.append('0');
hexString.append(hex);
}
//System.out.println("Hex format : " + hexString.toString());
}
catch(Exception e)
{
System.out.println(e);
}
return hexString.toString();
}
private String encryptPassword(String as_passwd) throws Exception
{
System.out.println("SysGenPassword..................encrypt...............");
String ls_return = "";
try
{
System.out.println( "Encrypting Password....." );
int li_len, li_count, li_Seed, li_passAsc;
li_len = as_passwd.length();
for(li_count = 0; li_count < li_len;li_count++)
{
Random li_Seed_r = new Random();
li_Seed = li_Seed_r.nextInt(10);
li_passAsc =(int) as_passwd.charAt(li_count);
li_passAsc = li_passAsc + li_Seed + li_count;
ls_return +=""+(char)(li_passAsc) +""+ (char)(li_Seed + li_count);
}
}
catch(Exception e)
{
System.out.println("Exception: SysGenPassword: encrypt:==>\n"+e.getMessage());
//throw e;
}
System.out.println("SysGenPassword..................encrypt.......["+ls_return+"]....");
return ls_return;
}
//End changes by Rakesh
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment