2

In my site i have a link Forgot Password when i click on this link a page will come so we fill emailId and send mail to particular gmailid(in this mail we have to generate a link). when we have click on generated link page open for reset password(like new password ar confirm password).

My problem is that i am successfully able to send mail but when click on link not able to find emailId for reset password. Gmail Link :

http://127.0.0.1:8888/abc.html?gwt.codesvr=127.0.0.1:9997#forgetPassword

client Code

sendButton.addClickHandler(new ClickHandler() {

    @Override
    public void onClick(ClickEvent event) {
        // TODO Auto-generated method stub

        greetServer.mailLinkSend(emailId.getText(),"http://"+Window.Location.getHost()+Window.Location.getPath()+Window.Location.getQueryString()+"#forgetPassword", new AsyncCallback<String>() {

            @Override
            public void onSuccess(String result) {
                // TODO Auto-generated method stub
                System.out.println("success"+result);
            }

            @Override
            public void onFailure(Throwable caught) {
                // TODO Auto-generated method stub
                System.out.println("fail");
            }
        });
    }
});

on server

public String mailLinkSend(String emailText, String link) {
               SecretKey key = KeyGenerator.getInstance("DES").generateKey(); 

// Create encrypter/decrypter class DesEncrypter encrypter = new DesEncrypter(key);

// Encrypt encrypted = encrypter.encrypt(emailText);

// Decrypt String decrypted = encrypter.decrypt(encrypted);

    String ss = "true";

            String emailMsgTxt = "Hi" + emailText + "\n" + "\n"
            + "Your Password Change Link\n" + link + "?id=" + encrypted
            + "\n Click on the above link to Reset your Password";
    String emailSubjectTxt = "Change Password Link";
    String emailFromAddress = "abc@gmail.com";
    String receipentList = emailText;

    try {
        MailUtility smtpMailSender = new MailUtility();
        smtpMailSender.postMail(receipentList, emailSubjectTxt,emailMsgTxt,   emailFromAddress);

    } catch (MessagingException messagingException) {}


    return ss;
}

MailUtility class

public class MailUtility {
    public String postMail(String recipients, String subject,
            String message, String from) throws MessagingException {

some code.... }

i have send emailId in encrypted form but i don't know how to save key for decrypted and also how to expire link after one time use and 48 hrs.

ruchi
  • 996
  • 12
  • 30
  • post some code for the above – Parvathy Jan 31 '13 at 05:38
  • u just paste code, I didn't get what happened – Parvathy Jan 31 '13 at 05:47
  • In client Side i make a link and send "http://"+Window.Location.getHost()+Window.Location.getPath()+Window.Location.getQueryString()+"#forgetPassword" and on server side using javax.mail send mail on gmail id. – ruchi Jan 31 '13 at 05:52
  • i mean explain your question with code. By giving the above details i cant tell anything – Parvathy Jan 31 '13 at 05:56
  • @Parvathy ok just check code and my problem is basically when i found link on my gmailid ank click this than how to know id.. – ruchi Jan 31 '13 at 06:08
  • come for chat http://chat.stackoverflow.com/rooms/23685/discusion-between-ruchi-and-parvathy – Parvathy Jan 31 '13 at 06:14

1 Answers1

1

So your problem with encryption and decryption

So the below code will help you

Note Constants.GWT_DES_KEY will be same on server and client

for example :

private final static byte[] GWT_DES_KEY = new byte[] { -110, 121, -65, 22, -60, 61, -22, -60, 21, -122, 41, -89, -89, -68, -8, 41, -119, -51, -12, -36, 19, -8, -17, 47 };

on the server:

  TripleDesCipher cipher = new TripleDesCipher();
    cipher.setKey(Constants.GWT_DES_KEY);
    try {
    enc = cipher.encrypt(String.valueOf(value));
    } catch (DataLengthException e1) {
    e1.printStackTrace();
    } catch (IllegalStateException e1) {
    e1.printStackTrace();
    } catch (InvalidCipherTextException e1) {
    e1.printStackTrace();
    }

On the client, make sure you inherit the module:
<inherits name='com.googlecode.gwt.crypto.Crypto'/>
Then:

  TripleDesCipher cipher = new TripleDesCipher();
    cipher.setKey(Constants.GWT_DES_KEY);
    String dec ="";
    try {
    dec = cipher.decrypt(enc);
    } catch (DataLengthException e) {
    e.printStackTrace();
    } catch (IllegalStateException e) {
    e.printStackTrace();
    } catch (InvalidCipherTextException e) {
    e.printStackTrace();
    }
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • thanks.This is another good useful information for me. but my problem is not related to client server encryption. I m just asking how to save DES generate key for decryption. – ruchi Jan 31 '13 at 08:35
  • need not to save the key use the same key while encryption and decryption ..give a standered secret byte array for GWT_DES_KEY. are you generating the key at run time with some of the user info ??then you have to store the key in DB and retrieve it after you recognize the email..with email-key pair – Suresh Atta Jan 31 '13 at 09:00